Reputation: 974
I am building a chat client for Android ICS
. I have a roster(contacts) activity which can lead to chat activity(after clicking an entry in the roster(contact) list). Then, one can chat and can come back to roster screen after clicking a button present on chat screen.
The flag used to start activities in the code for creating intent is : Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
There is also a search button on roster activity screen which takes us to search activity which in turn allows us to go to chat activity.
Flags used here are same. All three are singleTask.
Now the problem is when i go from roster activity to chat activity and then back to roster activity then everything is good. But when i go from roster activity to search activity, then to chat activity and then back to roster activity then roster activity gets recreated, i.e. oncreate()
function of roster is called. This does not happen in the other flow.
Can anyone explain this. Creating a new activity for search may not be appreciated but assuming its good, can reasons why this can happen?
Also ondestroy()
of roster activity is not called (since it is not compulsion).
Upvotes: 1
Views: 106
Reputation: 43524
You must always expect that onCreate is called at any point in time after resuming or otherwise returning to your activity from a different screen. Android may choose to terminate any activity that is paused, i.e. hidden from the user. When going back to that Activity, and if it had been destroyed, Android will recreate it by calling onCreate (and onRestoreInstanceState, which is why you should save volatile data that's supposed to outlive context changes in onRetainInstanceState.)
There is nothing absurd about this behavior, it's well documented as part of Android's activity life-cycle.
Upvotes: 2