Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

startActivity is always calling onDestroy on the original activity

Tags:

android

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

like image 531
LocoMike Avatar asked Jul 15 '13 21:07

LocoMike


People also ask

What happens when onDestroy is called?

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.

What is onDestroy () activity?

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.

What happens when an application calls startActivity for an activity that already has an instance running?

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.

Does onDestroy finish call?

finish() usually triggers a call to onDestroy() . Generally speaking, finish() will eventually result in onDestroy() being called.


1 Answers

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.

like image 179
Neil Avatar answered Sep 22 '22 12:09

Neil