【发布时间】:2012-05-24 20:11:40
【问题描述】:
我有 appwidgetprovider 类如下,它调用一个活动来打开
for (int widgetId : allWidgetIds) {
remoteViewParent = new RemoteViews(context.getPackageName(),R.layout.widget_initial_layout);
try{
Intent clickIntent = new Intent(context,Activity.class);//same class name is passed to give the call to itself
clickIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//PASSING ID HERE
clickIntent.putExtra("checkintent", ""+widgetId);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, clickIntent,PendingIntent.FLAG_UPDATE_CURRENT);
remoteViewParent.setOnClickPendingIntent(R.id.widget_img_logo, pendingIntent);
appWidgetManager.updateAppWidget(widgetId, remoteViewParent);
}catch (Exception e) {
}
}
我希望 Activity 在我的 Activity 类中接收 widgetId,所以我通过 putExtra() 传递它
在此之后,我一个一个地添加3 小部件,当我单击主屏幕上的任何小部件时,我只会获得最后添加的小部件的 ID(通过我的意图)
有没有办法区分对添加的特定小部件的点击,任何解决方法?
很久以前就开始关注这个了。
我想要这个用于 android 2.2 及更高版本。
欢迎任何建议
【问题讨论】:
标签: android android-widget android-pendingintent