Android multiple widget instance with same ID -
i have problem. checked lot of stackoverflow discutions, did not find correct solution me.
i have widget, openclosewidget 2 buttons,'open' , 'close'. have configure activity.
my problem last id of widget being used every widget.
here onupdate method:
@override public void onupdate(context context, appwidgetmanager appwidgetmanager, int[] appwidgetids) { log.i(log_tag, "[onupdate] appwidgetids.length = " + appwidgetids.length); (int : appwidgetids) { appwidgetid = i; log.d(log_tag, "[onupdate " + + "] widget id is: " + i); remoteviews views = new remoteviews(context.getpackagename(), r.layout.open_close_layout); xmppserviceinterface remoteservice = null; bindtoservice(remoteservice, context); opencloseinfo.setitem(appwidgetid, views, context, opencloseprovider.this, remoteservice, null); log.i(log_tag, "[onupdate " + + "] opencloseinfo.size(): " + opencloseinfo.size()); opencloseinfo.get(appwidgetid).first.getremoteviews().setonclickpendingintent(r.id.openbutton, getpendingselfintent(context, context.getresources().getstring(r.string.label_open), i)); opencloseinfo.get(appwidgetid).first.getremoteviews().setonclickpendingintent(r.id.closebutton, getpendingselfintent(context, context.getresources().getstring(r.string.label_close), i)); appwidgetmanager.updateappwidget(i, opencloseinfo.get(i).first.getremoteviews()); settodefault(context, i); } }
my pending method:
private pendingintent getpendingselfintent(context context, string action, int id) { intent intent = new intent(context, opencloseprovider.class).setaction(action) .setdata(uri.withappendedpath(uri.parse("://widget/id/"), string.valueof(id))) .putextra(appwidgetmanager.extra_appwidget_id, id).addflags(intent.flag_activity_new_task); pendingintent temp = pendingintent.getbroadcast(context, id, intent, 0); log.d(log_tag, "[getpendingselfintent " + appwidgetid + "]" + temp); return temp; }
the problem in onreceive() last widget id. how can set correct id onrecive()?
Comments
Post a Comment