I have an application with 3 tabs with one activity per tab. When I am switching between first two activities, the activity, which is going to background passes the onPause() state, while the new one becomes active and onResume() is called. That’s good, because both activities have a complex UI and rendering them takes 2-3 seconds, but when they are kept in paused state, they are resumed quickly.
But when I click on the 3rd tab, then the application behavior is different, the activity, which is going to background, is completely destroyed (it passes onPause(), onStop() and onDestroy()).
Any idea why there is difference in behavior? Is there a way to force the activity to remain in a paused state when user switches to another activity within the application?
Thanks
STeN
This behaviour can even be different on another device or in any other context (different amount of available memory, etc).
You have the guarantee that
onResume()is called when anActivityis going foregroundonPause()is called when theActivityis going background,and this is the only guarantee you have. (More details on the
Activitylifecycle here).So you can make absolutely no assumption about the calling of
onStop()andonDestroy(). They may be called or not each time you are switching from a tab to another, and your application needs being able to handle this.