Removing an entry from an Bundle (i.e. extras) doesn't seem to work in combination with the back button

android, android-activity, android-intent

Solution

Because `getExtras()` creates a copy of intent extras.

You have to do like this

getIntent().removeExtra("smsChallenge");

Docs : http://developer.android.com/reference/android/content/Intent.html#removeExtra(java.lang.String)

Problem

I have a BroadcastReceiver that listen to incoming SMS'. If the message is from a certain sender, the BroadcastReceiver starts my app with the following code: ``` final Intent activityIntent = new Intent(context, MainActivity.class); activityIntent.putExtra("smsChallenge", smsText); activityIntent.putExtra("smsSenderNumber", senderMobilNumber); activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); activityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); context.startActivity(activityIntent); ``` In the MainActivity of my app (i.e. in `onCreate()`), I extract the value `smsChallenge` out of the intent and DELETE IT AFTER THE EXTRACTION with the following code: ``` Bundle extras = getIntent().getExtras(); if (extras != null) { smsChallenge = extras.getString("smsChallenge"); extras.remove("smsChallenge"); } ``` So my app gets started from the SMS and runs fine... But if I choose to press the BACK button and restart the application (i.e. through the Taskmanager), the value `smsChallenge` is still in the bundle `extras`. This means, my restarted app thinks that it is re-started because of a new SMS which is not true... Any ideas why removing the key-value from the bundle doesn't seem to work when using the BACK button and restarting the app again?

Original source

Related problems