如何将特定的挂起意图绑定到多小部件上特定小部件上的特定按钮..appwidget?
我正在开发一个小部件,它允许用户在屏幕上拥有多个小部件实例。每个 Widget id 都维护自己的配置文件。然而,由于某些奇怪的原因,我负责为每个小部件 id 单独设置按钮的代码不起作用,只有第一个小部件 id 链接到每个单独的小部件。下面是负责的代码。谁能看出问题出在哪里吗?
private void TieClicks(Context context){
RemoteViews rViews;
PendingIntent editPendingIntent= null;
// Intent updateintent = new Intent(context,SyncNoteWidget.class);
// updateintent.setAction(SyncNote_Action_Widget_Update);
// PendingIntent pendingupdateintent = PendingIntent.getBroadcast(context, 0, updateintent, 0);
// rViews.setOnClickPendingIntent(R.id.widgettextview , pendingupdateintent);
//
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
int[] ids = appWidgetManager.getAppWidgetIds(new ComponentName(context, SyncNoteWidget.class));
for (int i =0;i< ids.length;i=i+1){
int wId = ids[i];
rViews = new RemoteViews(context.getPackageName(),R.layout.widget);
editPendingIntent = makeControlPendingIntentActivity(context, wId);
Log.v("syncnote", "tieing " + String.valueOf(wId));
rViews.setOnClickPendingIntent(R.id.widgeteditbutton , editPendingIntent);
appWidgetManager.updateAppWidget(wId, rViews);
editPendingIntent= null;
}
}
private PendingIntent makeControlPendingIntentActivity(Context context,int appWidgetId) {
Intent active = new Intent(context, EditNote.class);
active.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
active.setAction(com.ntu.way2fungames.syncnote.SyncNoteWidget.SyncNote_Action_Edit);
active.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
return(PendingIntent.getActivity(context, 0, active, 0 ));
}
I have a Widget i am working on, that allows the user to have more then one instance of the widget on his screen. Each Widget id maintains its own configuration file. However for some odd reason my code that is responsible for setting up the buttons individually for each widget id is not working, only the first widget id is linked to each individual widget. below is the code that is responsible. Can anyone see where the problem is?
private void TieClicks(Context context){
RemoteViews rViews;
PendingIntent editPendingIntent= null;
// Intent updateintent = new Intent(context,SyncNoteWidget.class);
// updateintent.setAction(SyncNote_Action_Widget_Update);
// PendingIntent pendingupdateintent = PendingIntent.getBroadcast(context, 0, updateintent, 0);
// rViews.setOnClickPendingIntent(R.id.widgettextview , pendingupdateintent);
//
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
int[] ids = appWidgetManager.getAppWidgetIds(new ComponentName(context, SyncNoteWidget.class));
for (int i =0;i< ids.length;i=i+1){
int wId = ids[i];
rViews = new RemoteViews(context.getPackageName(),R.layout.widget);
editPendingIntent = makeControlPendingIntentActivity(context, wId);
Log.v("syncnote", "tieing " + String.valueOf(wId));
rViews.setOnClickPendingIntent(R.id.widgeteditbutton , editPendingIntent);
appWidgetManager.updateAppWidget(wId, rViews);
editPendingIntent= null;
}
}
private PendingIntent makeControlPendingIntentActivity(Context context,int appWidgetId) {
Intent active = new Intent(context, EditNote.class);
active.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
active.setAction(com.ntu.way2fungames.syncnote.SyncNoteWidget.SyncNote_Action_Edit);
active.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
return(PendingIntent.getActivity(context, 0, active, 0 ));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是由于某种原因“PendingIntent.getActivity”正在重复使用第一个 PendingIntent ..上帝知道为什么。修复如下,只需在调用中添加一些随机数据即可。
The problem was that for some reason "PendingIntent.getActivity" was re-using the first PendingIntent.. God knows why. The fix is below, simply add some random data to the call.
如果您包含正在创建的日志条目,这将会有所帮助:
这可以回答重要的问题:
int[] ids 中有多少个值?
R.layout.widget 中有什么?
您的小部件的图片也会有所帮助。一张图胜过一千个字……
It would help if you included the log entries you're creating with:
That could answer the important question:
How many values are in: int[] ids ?
What is in R.layout.widget ?
A picture of your widgets would help too. A picture is worth a thousand words...