android - How can I update widget from fragment? -
solutions update activity not work. code not work in app:
intent intentq = new intent(getactivity(), widget.class); intentq.setaction("android.appwidget.action.appwidget_update"); int ids[] = appwidgetmanager.getinstance(getactivity().getapplication()).getappwidgetids(new componentname(getactivity().getapplication(), widget.class)); intentq.putextra(appwidgetmanager.extra_appwidget_ids,ids); getactivity().sendbroadcast(intentq);
i use method in fragment in order update widget clicking updatebutton. hope method helps solve problem.
private void updatewidgetscreen(string updatedata) { appwidgetmanager appwidgetmanager = appwidgetmanager.getinstance(parentactivity); remoteviews remoteviews = new remoteviews(parentactivity.getpackagename(), r.layout.widget); componentname thiswidget = new componentname(parentactivity, widgetprovider.class); remoteviews.settextviewtext(r.id.remaining_money, updatedata); intent intent = new intent(parentactivity, widgetservice.class); intent.putextra(appwidgetmanager.extra_appwidget_id, mainutils.getwidgetid(prefs)); intent.setdata(uri.parse(intent.touri(intent.uri_intent_scheme))); remoteviews.setremoteadapter(mainutils.getwidgetid(prefs), r.id.list_view, intent); intent clickintent = new intent(parentactivity, mainactivity.class); pendingintent clickpi = pendingintent.getactivity(parentactivity, 0, clickintent, pendingintent.flag_update_current); remoteviews.setpendingintenttemplate(r.id.list_view, clickpi); appwidgetmanager.updateappwidget(thiswidget, remoteviews); log.e("updatewidgetscreen", updatedata+" updatedata - widgetid: "+ mainutils.getwidgetid(prefs)); }
Comments
Post a Comment