Android: detect restarted service with START_REDELIVER_INTENT flag
<p>My widget has a service attached to it to process various click "commands" which are passed through its intent.  I've also set <code>return START_REDELIVER_INTENT;</code> for the case of when the service is restarted to not give a nullPointerException when calling intent.getAction(); and the like.  The problem is, when the last intent was sent by one of the setOnClickPendingIntent calls I have, then when the service is restarted, it acts as if the user had clicked one of the viewId's.  e.g.</p>

<pre><code>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));
</code></pre>

<p>Where makeControlPendingIntent is:</p>

<pre><code>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));
    }
</code></pre>

<p>Is there something I can do to check if the service is being restarted so as to not run any of those commands in the case where Android restarts my service?</p>
