onDestroy function in my activity class gets called when screen sleeps or if screen is locked. I know this should not happen as the flow of control is supposed to be onPause()->onStop(). On locking screen the flow of control is like this: onPause()->onStop()->onDestroy(). I have given android:configChanges="orientation|keyboardHidden"
in my android manifest as suggested by answers to similar questions but that did not work. isFinishing() function returns false when checked from onStop().
Can anyone please help me solve this issue.
If onDestroy() is called as the result of a configuration change, the system immediately creates a new activity instance and then calls onCreate( ) on that new instance in the new configuration.
onPause() and onStop() will not be invoked if finish() is called from within the onCreate() method. This might occur, for example, if you detect an error during onCreate() and call finish() as a result. In such a case, though, any cleanup you expected to be done in onPause() and onStop() will not be executed.
2. In post-Honeycomb versions of Android onStop() and onDestroy() are both potential-killer methods. Thus there is no guarantee that onDestroy() will be called.
Once onStop() is called then onRestart() can be called. onDestroy() is last in the order after onStop(). onDestory() is called just before an activity is destroyed and after that it is gone it is not possible to resurrect this. Simply destroyed and buried!
I had the same problem here:
Activity Lifecycle X Power Button X Lock Screen
The solution was to add the configChanges like you did, but you are missing the screenSize type:
android:configChanges="orientation|keyboardHidden|screenSize"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With