How to clear Intent that started Activity?
I had similar problem. This helped me. Maybe you have to also use onSaveInstanceState(Bundle outState) and add extra data to the bundle so inState is not null, not sure.
Intent activityIntent = null; // Subsequent times it's null
@Override
protected void onCreate(Bundle inState) {
super.onCreate(inState);
.
.
if (inState!=null) {
/*Recreating activity with a saved state*/
} else {
/*Creating activity*/
activityIntent = getIntent(); // First time through intent is used
/*Get your Extra Intent data here. You will be capturing data on 1st creation. */
}
Do not use setIntent(null)
. It seems that while it may work sometimes, under some conditions the original intent may come back.
Instead, call setIntent()
with a simple intent that doesn't have an action, data or extras, such as new Intent(Context, Class)
.
Indeed, the use of setIntent()
was actually not a good API design decision in the first place. Instead, as dcg noted, be sure you only check your intent the first time, when your savedInstanceState
is still null.