tags:

views:

45

answers:

1

Is this normal.

The docs say

"The onStart() and onStop() methods can be called multiple times, as the activity alternates between being visible and hidden to the user"

When I press the back button an it will go back to the previous activity which totally covers the old one.

What is going on here?

+2  A: 

You want onPause(), not onStop(). onStop is called just before the activity is destoryed, when the system is low on memory. onPause is called whenever the user navigates away from your activity. See diagram at http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle.

QRohlf
Thanks, in the diagram it says "Activity is no longer visible" and then onStop() occurs, so what does "no longer visible" mean then? I would have thought that going to an activity means no longer visible.
jax
In my understanding, android makes a distinction between "another activity in the foreground" (onPause is called, but your activity continues to have a VM and operate), and "activity is no longer visible because it is about to be killed" (onStop, and later, onDestroy is called). So onPause will be called every time your activity is hidden, immediately, whereas onStop is called less often. This is just my take on things, and is probably somewhat inaccurate, but the android docs say "The foreground lifetime of an activity happens between a call to onResume until a corresponding call to onPause."
QRohlf