views:

114

answers:

2

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? :\

+1  A: 

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: http://stackoverflow.com/questions/3063410/child-activity-in-android/3065187#3065187 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.

Joubarc
Well, that particular question is mine as well :D I just reposted the follow-up one cuz back there I didn't know the reason this was happening and I wanted to make a clean version :)But as you can see, I've used startActivityforResult ;)
Martin Marinov
Sorry about that- I should check who is asking the question first :-)
Joubarc
Well, I'll try...
Martin Marinov
A: 

I used Dialog instead of an Activity and everything worked well so I'm leaving it like that.

Martin Marinov