android - appwidget not updating itself -
i working on android appwidget , there issues updating appwidget periodically . changed updating period more 30 minutes . still not updating widget
public class mywidgetprovider extends appwidgetprovider { final static string item_click_action = "itemclick"; public static final string toast_action = "toast_action"; broadcastreceiver receiver; public void onupdate(context context, appwidgetmanager appwidgetmanager, int[] appwidgetids) { final int n = appwidgetids.length; (int = 0; < n; i++) { int appwidgetid = appwidgetids[i]; log.e("called", "omupdate"); remoteviews views = new remoteviews(context.getpackagename(), r.layout.widget_lay); views.settextviewtext(r.id.textview1, "floating text displayed here .. daily thoughts"); intent intent = new intent(context, remoteserviceemin.class); intent.putextra(appwidgetmanager.extra_appwidget_id, appwidgetid); // intent.setdata(uri.parse(intent.touri(intent.uri_intent_scheme))); views.setremoteadapter(r.id.gridview, intent); // inflating list remote view intent intentlist = new intent(context, listinflater.class); intentlist.putextra(appwidgetmanager.extra_appwidget_id, appwidgetid); // intent.setdata(uri.parse(intent.touri(intent.uri_intent_scheme))); views.setremoteadapter(r.id.listview, intentlist); // setting onclick on gridview intent itemclickintent = new intent(context, mywidgetprovider.class); itemclickintent.setaction(item_click_action); itemclickintent.putextra(appwidgetmanager.extra_appwidget_id, appwidgetids[i]); pendingintent itemclickpendingintent = pendingintent.getbroadcast( context, 0, itemclickintent, pendingintent.flag_update_current); views.setpendingintenttemplate(r.id.gridview, itemclickpendingintent); intent toastintent = new intent(context, mywidgetprovider.class); toastintent.setaction(mywidgetprovider.toast_action); toastintent.putextra(appwidgetmanager.extra_appwidget_id, appwidgetids[i]); intent.setdata(uri.parse(intent.touri(intent.uri_intent_scheme))); pendingintent toastpendingintent = pendingintent.getbroadcast( context, 0, toastintent, pendingintent.flag_update_current); views.setpendingintenttemplate(r.id.ll, toastpendingintent); // appwidgetmanager.updateappwidget(appwidgetids[i], v); // appwidgetmanager.updateappwidget(appwidgetids[i], views); appwidgetmanager.updateappwidget(appwidgetid, views); } super.onupdate(context, appwidgetmanager, appwidgetids); } @override public void onreceive(context context, intent intent) { // todo auto-generated method stub if (intent.getaction().equals(item_click_action)) { bundle extras = new bundle(); extras.putstring("text", intent.getextras().getstring("text")); intent actintent = new intent(); actintent.setclass(context, configurationactivity.class); actintent.addflags(intent.flag_activity_new_task); actintent.putextras(extras); context.startactivity(actintent); } else if (intent.getaction().equals(toast_action)) { toast.maketext(context, "dfjdsfl", toast.length_short).show(); } else { super.onreceive(context, intent); } }
}
this appwidget class, can't track why isnt updating after android:updateperiodmillis="50000"
thanks in advance ..
the minimum actual time widget update 30 minutes avoid poor programmed widgets dry battery. frequent update of widget use alarmmanager overcome .
public void onupdate(context context, appwidgetmanager appwidgetmanager, int[] appwidgetids){ long interval = 50000; intent in = new intent(context, widgetclass.class); in.setaction("widgetupdate"); pendingintent pi = pendingintent.getservice(context, 0, in, 0); alarmmanager alarm = (alarmmanager) context.getsystemservice(context.alarm_service); alarm.setrepeating(alarmmanager.elapsed_realtime, systemclock.elapsedrealtime(),interval, pi); //add remaining code here } public void onreceive(context context, intent intent) { if (intent.getaction().equals("widgetupdate")) { watchwidget = new componentname(context, widgetclass.class); remoteviews views = new remoteviews(context.getpackagename(), r.layout.widget_lay); (appwidgetmanager.getinstance(context)).updateappwidget( watchwidget, views); } declare receiver action in menifest file
Comments
Post a Comment