My widget has a service associated with it to handle various click commands that are transmitted as it wishes. I also set return START_REDELIVER_INTENT;
for the case when the service is restarted so as not to throw a nullPointerException when calling aim.getAction (); etc. The problem is that when the last intention was sent by one of the setOnClickPendingIntent calls that I have, then when the service restarts, it acts as if the user clicked on one of the viewId. eg.
String command = intent.getAction(); int appWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID); if(command.equals("some command")){ //do something } ... remoteView.setOnClickPendingIntent(R.id.viewId,MyClass.makeControlPendingIntent(getApplicationContext(),"some command",appWidgetId));
Where makeControlPendingIntent:
public static PendingIntent makeControlPendingIntent(Context context, String command, int appWidgetId) { Intent active = new Intent(context,MyService.class); active.setAction(command); active.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); Uri data = Uri.withAppendedPath(Uri.parse("myclass://widget/id/#"+command+appWidgetId), String.valueOf(appWidgetId)); active.setData(data); return(PendingIntent.getService(context, 0, active, PendingIntent.FLAG_UPDATE_CURRENT)); }
Is there something I can do to check if the service restarts, so as not to run any of these commands in case Android restarts my service?
source share