When calling startActivity(Intent intent) from my activity, onDestroy() method is always being called on it, so I lose my state of fragments, etc...
My understanding is that onStop should be called, and onDestroy could or could not be called. But my experience is that the original activity is always being destroyed.
I understand that if I have an activity with a listView, with an adapter, etc... Android does not expect me to sve the state of the adapter simply because I push another activity on top of this one, right?
Am I correct? What could be triggering this behavior?
Thank you
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.
onDestroy() is a method called by the framework when your activity is closing down. It is called to allow your activity to do any shut-down operations it may wish to do.
If you call startActivity() for an Activity with default launch mode(i.e, you didn't mention any launch mode in either in manifest or in Intent) a new instance of the activity is created. For example, A launched B and again B launched A then Activity stack would be A - B - A.
finish() usually triggers a call to onDestroy() . Generally speaking, finish() will eventually result in onDestroy() being called.
On some devices (Galaxy S2 etc.), there is a setting which can cause activities to be destroyed whilst debugging. You can find this in:
settings > developer options > go down to the bottom under apps section >
Do not keep activities
Uncheck this option, to stop activities always being destroyed when you leave them.
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