【发布时间】:2010-03-18 17:09:41
【问题描述】:
我saw this topic 并按照描述实现了 IntentService,但是如果我想要更多的那个按钮怎么办?如何区分按钮? 我正在尝试 setFlags,但在 onHandleIntent() 方法中无法读取:
public static class UpdateService extends IntentService {
...
@Override
public void onHandleIntent(Intent intent) {
ComponentName me = new ComponentName(this, ExampleProvider.class);
AppWidgetManager manager = AppWidgetManager.getInstance(this);
manager.updateAppWidget(me, buildUpdate(this));
}
private RemoteViews buildUpdate(Context context) {
RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.main_layout);
Intent i = new Intent(this, ExampleProvider.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
updateViews.setOnClickPendingIntent(R.id.button_refresh, pi);
i = new Intent(this, ExampleProvider.class);
pi = PendingIntent.getBroadcast(context, 0, i, 0);
updateViews.setOnClickPendingIntent(R.id.button_about, pi);
return updateViews;
}
}
在这段小代码中,我有两个与 setOnClickPendingIntent 链接的 PendingIntent,我可以区分这个 Intent 用于不同的操作和处理吗? 感谢帮助
【问题讨论】:
-
显然,我找到了答案。我们必须按照此处helloandroid.com/files/xmaswidget/android_howto-hellowidget.pdf 的描述注册意图过滤器。现在我会尝试然后写下结果。