SETUP One Activity, SingleTop, receives an intent from a notification. Intent is consumed by activity. User hits back button to end the activity. onDestory gets called and isFinishing() returns true. Long press Home key to bring up recent apps. Launch previously closed application.
Similar situation occurs with onNewIntent when onStop is called after user presses home key on activity.
Problem Upon recreation of the activity after it's finished, the same intent from the notification is used. I don't want this. Is there a way to tell the system that we already consumed that notification so stop giving it to the activity? Work around? Suggestions?
What I have Tried
This question is very similar to this one: http://grokbase.com/t/gg/android-developers/119jyzf492/getintent-removeextra-in-activity-doesnt-work-for-android-launchmode-“singletask”
This is a WORK AROUND - and not a solution IMO.
Remember the problem was onCreate() and onNewIntent() kept giving the activity the same intent no matter what (Nothing was sticky). The worst offender was onCreate() because the Bundle savedInstanceState was always null.
I created a serializable (lets call is sFOO) class that holds intent actions and a time stamp from the intent extras. During onCreate() I load this serialized class (sFOO). During onStart() i compare sFOO to the intent being processed. If everything is new, i know the intent needs to be handled and sFoo updated then saved. If not, I disregard the intent.
In onStart()
Intent activityIntent = this.getIntent();
if (activityIntent != null)
{
if (activityIntent.getAction() != null)
{
boolean newIntent = false;
//Is the intent action being processes same as previous?
if (activityIntent.getAction().compareTo(this.mLastProcessedIntent.mLastIntentProcessedAction) == 0)
{
if (activityIntent.getExtras() != null)
{
//Is the intent time stamp being processed same as previous?
if (activityIntent.getExtras().getLong(TIME_STAMP_KEY) != this.mLastProcessedIntent.mLastIntentProcessedTimestamp)
{
newIntent = true;
}
}
}
else
{
Log.d(TAG,"Last processed intent action does not equal new one.");
newIntent = true;
}
if (newIntent)
{
updateAndSaveProcessedIntent();
/*YOUR CODE HERE TO HANDLE INTENT*/
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With