Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting old intent extras in onResume() after startActivity(newIntent)

Tags:

android

In the calling activity, I have the following code:

Intent intent = new Intent();
intent.setClass(CallingActivity.this, CalledActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(key, new_value);
startActivity(intent);

After the startActivity(intent) is called, the control goes to onResume() of the CalledActivity.

However, in the onResume() of the CalledActivity, getIntent() gives me the old intent and not the new intent as set by the CallingActivity.

How can I get the new intent in onResume() of the CalledActivity??

like image 669
user1300756 Avatar asked Mar 29 '12 13:03

user1300756


2 Answers

You should try to override the onNewIntent (Intent intent) method of Activity, and use setIntent(Intent) to update the intent.

like image 103
dreamtale Avatar answered Oct 03 '22 19:10

dreamtale


To expand on dreamtale's answer, just add the following method to your Activity.

@Override
public void onNewIntent (Intent intent) {
    setIntent(intent);
}
like image 33
Takaitra Avatar answered Oct 03 '22 19:10

Takaitra