I have a main activity which calls a child one via
Intent I = new Intent(this, Child.class);
startActivityForResult(I, 0);
But as soon as Child becomes visible the main activity gets its onStop and immediately after that onDestroy method triggered. And as soon as I call finish() within the Child activity or press the back button, the Child activity closes and the home screen shows (instead of the main activity).
How can I prevent the main activity from being destroyed? :\
If you launch a child Activity from which you expect return data, you’ll probably want to use
startActivityforResultinstead.You may want to check this question: Child Activity in Android as it seems to be the same problem.
Edit:
As for what’s happening here, you could place code in the
onStop()and/oronDestroy()methods to investigate – at least a call toisFinishing()to check why the Activity is being destroyed.You should also use adb logcat from your host machine to check the logcat in case it holds more information – and maybe use
Log.d()(the result goes into logcat as well) instead of toasts to make sure you don’t miss them.