android - AppWidget PendingIntent not working after Launcher restart -
i have appwidget 2 pending intents. work of time, after while stop responding. thing have been able pinpoint crippled after launcher restart, i.e. use launcher pro, , fiddle settings , have restart it. after don't work @ all.
here onrecieve() , onupdate() methods:
public void onreceive(context context, intent intent) { super.onreceive(context, intent); string action = intent.getaction(); if(action.equals("android.tristan.widget.digiclock.click")) { packagemanager packagemanager = context.getpackagemanager(); intent alarmclockintent = new intent(intent.action_main).addcategory(intent.category_launcher); string clockimpls[][] = { {"htc alarm clock", "com.htc.android.worldclock", "com.htc.android.worldclock.alarmclock" }, {"standar alarm clock", "com.android.deskclock", "com.android.deskclock.alarmclock"}, {"froyo nexus alarm clock", "com.google.android.deskclock", "com.android.deskclock.deskclock"}, {"moto blur alarm clock", "com.motorola.blur.alarmclock", "com.motorola.blur.alarmclock.alarmclock"} }; boolean foundclockimpl = false; for(int i=0; i<clockimpls.length; i++) { string vendor = clockimpls[i][0]; string packagename = clockimpls[i][1]; string classname = clockimpls[i][2]; try { componentname cn = new componentname(packagename, classname); activityinfo ainfo = packagemanager.getactivityinfo(cn, packagemanager.get_meta_data); alarmclockintent.setcomponent(cn); foundclockimpl = true; } catch (namenotfoundexception e) { log.d(logtag, "error," + vendor + " not exist"); } } if (foundclockimpl) { vibrator vibrator = (vibrator) context.getsystemservice(context.vibrator_service); vibrator.vibrate(50); final remoteviews views = new remoteviews(context.getpackagename(), layoutid); views.setonclickpendingintent(r.id.toprow, pendingintent.getactivity(context, 0, new intent(context, digiclock.class).setflags(intent.flag_activity_new_task), pendingintent.flag_update_current)); appwidgetmanager.getinstance(context).updateappwidget(intent.getintarrayextra(appwidgetmanager.extra_appwidget_ids), views); alarmclockintent.setflags(intent.flag_activity_new_task); context.startactivity(alarmclockintent); } } } public void onupdate(context context, appwidgetmanager appwidgetmanager, int[] appwidgetids) { super.onupdate(context, appwidgetmanager, appwidgetids); context.startservice(new intent(updateservice.action_update)); context.startservice(new intent(context, screenupdateservice.class)); final int top = appwidgetids.length; final int bottom = appwidgetids.length; (int i=0; i<top; i++) { int[] appwidgetid = appwidgetids; final remoteviews top=new remoteviews(context.getpackagename(), layoutid); intent clickintent=new intent("android.tristan.widget.digiclock.click"); pendingintent pendingintentclick=pendingintent.getbroadcast(context, 0, clickintent, 0); top.setonclickpendingintent(r.id.toprow, pendingintentclick); appwidgetmanager.updateappwidget(appwidgetid, top); } (int i=0; i<bottom; i++) { int[] appwidgetid = appwidgetids; remoteviews bottom=new remoteviews(context.getpackagename(), layoutid); intent clickintent=new intent("android.tristan.widget.digiclock.click_2"); pendingintent pendingintentclick=pendingintent.getbroadcast(context, 0, clickintent, 0); bottom.setonclickpendingintent(r.id.bottomrow, pendingintentclick); appwidgetmanager.updateappwidget(appwidgetid, bottom); } } i have read putting intents in service, have tried , failed. appreciated.
as i've written here should produce single instance of remoteview.
Comments
Post a Comment