Reputation: 1197
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? :\
Upvotes: 0
Views: 766
Reputation: 564
check androidmanifest nohistory=true and that made the OS destroy the activity before the result. that might be one of the reason for your problem.
Upvotes: 0
Reputation: 1197
I used Dialog instead of an Activity and everything worked well so I'm leaving it like that.
Upvotes: 0
Reputation: 1216
If you launch a child Activity from which you expect return data, you'll probably want to use startActivityforResult
instead.
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/or onDestroy()
methods to investigate - at least a call to isFinishing()
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.
Upvotes: 1