According to http://developer.android.com/training/basics/activity-lifecycle/recreating.html
There are various ways to trigger activity recreation.
One of the obvious observations is that, for restore activity from long pressed home, it will destroy and re-create Application as well.
No, it will not.
If your process was terminated, then when a new process is created for you (not matter how you launch the app), a new Application
is created as part of that new process. This does not directly have anything to do with "restore activity from long pressed home".
May I know, how can Activity or Fragment differentiate both cases?
Ideally, they don't care. The only reason they would care is if they are dependent upon static data members, which may or may not be initialized, in which case the way that you are using those static data members is problematic.
My previous assertion, that savedInstanceState
would be non-null
, is incorrect, and for that I apologize. The primary scenario for savedInstanceState
is a configuration change. However, I was forgetting that launching from the recent-tasks list ("restore activity from long pressed home") will also pass in the last saved instance state. Launching by other means, such as from the home screen launcher, would pass in null
for savedInstanceState
.
If you absolutely must distinguish between your-process-was-terminated and other scenarios, check some static data member to see if it is initialized or not.
check this out -https://developer.android.com/reference/android/app/Activity#isChangingConfigurations()
You can simply save value returned by isChangingConfigurations()
in bundle and then check it in onCreate