This took me awhile to understand and I will report it as a bug if I'm
not corrected.
You only need a basic new project (sdk 1.5r3) with two activty
classes. A root/launcher activity with a button to start a second
activity (of a different class). Everything else on default. Use the
following line to start the second activity:
this.startActivity(new Intent(this, SecondActivity.class).setFlags
(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
That's it for setup.
Now launch the app on to a device or emulator, launch from any state,
fresh boot, Run command, it's irrelevant. Follow these steps:
1. Press button to start second activity.
2. Press the physical Back key.
3. Press button to start second activity.
4. ActivityManager will print: Starting activity: Intent
{ flags=0x20000 comp={yourproject/yourproject.SecondActivity} }
5. Second activity will NOT display.
I did a lot of debugging and I think I've found the reason, though I
do not know the underlying cause, this would be something deeper in
the OS.
Between step 2 & 3, the normal behaviour seems to that the
SecondActivity only reaches the onPause() method, even though
isFinishing() returns true. Now if you do not have the reorder flag,
what normally happens is a new instance of the activity is created and
the old continues destroying from onPause(). But if you do, the old
activity is still at onPause() and it also has isFinishing() true, so
it is not brought back forward as I assume it is marked dead but also,
a new instance is not created (which I believe is a bug/mistake).
It will be forever stuck in this state UNTIL you make any other action
on the activity stack (press back again, launch a 3rd activity if you
set it up etc), then it will get the message to continue with the
destroy cycle. But this is not really a viable solution, it's a hack
and not always an option, also to a user, the app just looks broken.
It's also possible to continually get back in this state, requiring
the hack each and every time.
I'm not really sure why the SecondActivity is not fully destroyed when
the Back key is pressed? What is the purpose of holding it at onPause
()? If there is some purpose, can we also have a flag that overrides
that decision and always *instantly* performs the destroy cycle on
Back key.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---