开发者

Prevent an Activity from being killed by the OS while starting a child activity

开发者 https://www.devze.com 2023-01-04 02:57 出处:网络
I have a main activity which calls a child one via Intent I = new Intent(this, Child.class); startActivityForResult(I, 0);

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 be开发者_如何转开发comes 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 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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消