marioosh
marioosh

Reputation: 28556

Bring to front Activity and getting extras

How to get extras from intent, when i use flag Intent.FLAG_ACTIVITY_REORDER_TO_FRONT ? Is this possible ?

Intent i = new Intent(ctx, MyActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
i.putExtra("a", "abc");
startActivity(i);       

In MyActivity i get null:

@Override
protected void onResume() {
    super.onResume();
    Log.i(TAG, getIntent().getExtras()+""); // <- get null
}

Upvotes: 2

Views: 912

Answers (2)

Farouk Touzi
Farouk Touzi

Reputation: 3456

your first activity starts MyActivity using Intent.FLAG_ACTIVITY_REORDER_TO_FRONT. This means that if there is already an active (non-finished) instance of MyActivity in the task stack, this instance of the activity will simply be moved to the front (top of the activity stack). In this case, onCreate() will not be called on MyActivity, because it isn't recreating the activity. Instead onNewIntent() will be called. You have not overridden this method in MyActivity.

You should override onNewIntent() and extract your data from the extras that are passed in the Intent argument that you receive in onNewIntent().

Upvotes: 1

Luvie
Luvie

Reputation: 126

override Activity.onNewIntent() method in MyActivity

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);

    // something you want
}

normal onResume() lifecycle will follow after onNewIntent() is called.

Upvotes: 4

Related Questions