Activity ignore intent's extra fields
Posted
by ced
on Stack Overflow
See other posts from Stack Overflow
or by ced
Published on 2010-05-26T10:08:46Z
Indexed on
2010/05/26
10:11 UTC
Read the original article
Hit count: 209
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?
© Stack Overflow or respective owner