Thank you for the answer, it's invaluable. I've 3 quick questions, I
would even appreciate even "Yes-no" answers if you can afford the
time.
> On Mon, Apr 23, 2012 at 4:10 PM, Tamás Kovács
> <
falcon.firebre...@gmail.com>wrote:
>
> > I've an app with two activities: "A" and "B".
> > "A" uses startActivityForResult() to spawn "B" i.e. it waits for "B".
> > Now, assume that "B" is in foreground. Assume the Android system
> > decides to free up memory. In theory, can it destroy (onDestroy())
> > activity "A" without also destroying "B"? I suppose yes.
>
> No, it cannot. To free up memory, the operating system kills whole
> processes, not individual components. Assuming that you are not declaring
> A and B to run in different processes, you will never see A killed for
> memory without B also going away.
But, due to the activity stack, the opposite must be true (i.e. B gets
killed but A doesn't when A has finished), am I right? You mentioned
one of the very few scenarios of onDestroy(). I'm experiencing
another: when "B" finishes, I see B.onDestroy() in logcat. Exactly as
the "Tasks and Back Stack" of the docs says.
You mention that the OS kills processes for memory, not components. My
initial confusion was because of this (from the docs): "An empty
process is one hosting no activities or other application components."
This implies that it's possible that a process hosts zero Activities
(but still retains the state of my static variables, as they are not
tied to any Activity).
Based on your answer, I would think that the following statement is
correct: "if all my Activities (of the same app) are destroyed by
Android, then my process will be destroyed too". Is this true?
> What *can* happen is that the orientation of the device is changed on the
> fly, or some other aspect of the global configuration (such as the locale).
My app is a complex game, which forces "landscape" orientation, so I
treat it manually, as you mention. It will be probably ignore all
other configuration changes too, but it can't see into the future, so
I've an interesting problem: assume the player is in the middle of a
strategic battle, and a configuration change occurs (that my app can't
ignore because it doesn't know it exists). This will cause a restart,
as you've explained. In the game, our philosophy is that if the game
starts with onCreate() (for any reason) then we start with the main
menu and the user can resume the game there; but if the interrupted
game only returns with onStart() or onResume(), then we jump back to
the strategic battle (with gamepaused state, of course) without
displaying the main menu. Question: Is there a way to detect that my
game was restarted due to a config change? (and e.g. not because it
was killed by the system or the phone was suddenly shut down).