tags:

views:

90

answers:

2

For example,

In an ActivityA there's a button to create an Intent that will start ActivityB in a new task, like this:

Intent i = new Intent(this, ActivityB.class);
i.setData(Uri.parse("http://www.google.com"));
long timestamp = System.currentTimeMillis();
i.putExtra("ts", timestamp);
i.addFlag(Intent.FLAG_ACTIVITY_NEW_TASK);
Log.d(TAG, "Sending: " + timestamp);
startActivity(i);

Then in ActivityB's onResume() method, there's this code to check the timestamp:

long timestamp = getIntent().getExtras().getLong("ts");
Log.d(TAG, "Receiving: " + timestamp);

Now the first time I invoke ActivityB from ActivityA I get the following logs:

Sending: 120006000
Receiving: 120006000

Then if I left ActivityB running in the background (by pressing Home button), and start ActivityA then invoke ActivityB again, the following is printed:

Sending: 120013000
Receiving: 120006000

It seems although ActivityB is brought to front by the new Intent. The extra field in the intent is being left behind.

Is this a bug or an intended behavior?

A: 

Maybe you should listen to onNewIntent not only to onResume?

Fedor
As a matter of fact, I've actually also tried to override onNewIntent() with FLAG_ACTIVITY_SINGLE_TOP, but the intent being passed in is still the old one.
ced
Ah, sorry, my mistake, onNewIntent() can in fact get the new extra data, thanks for helping =)
ced
+1  A: 

just read the documentation:

http://developer.android.com/reference/android/app/Activity.html#getIntent%28%29

getIntent() returns the Intent which started the activity. If the activity is running already in the backgroud, then you don't start the activity B, but you bring it to the front.

Roflcoptr
Yes, but since the new intent bring it to the front, I thought it would be reasonable to assume that will replace the old intent.
ced
ah ok. i think it's a feature and not a bug ;)
Roflcoptr