在进程被终止后不会调用onActivityResult

时间:2021-04-18 20:25:29

I have a main activity (Main) and another activity (Sub) that is called from Main by

我有一个主要活动(Main)和另一个从Main by调用的活动(Sub)

startActivityForResult(new Intent(this, SubActivity.class), 25); 

When I'm at Sub, and I kill the process (using a task manager or by adb shell kill <pid>), and I re-open the application, I'm taken immediately to Sub.

当我在Sub时,我终止进程(使用任务管理器或adb shell kill ),然后我重新打开应用程序,我立刻被带到了Sub。

In Sub I have this code to call back to the Main activity:

在Sub中我有这个代码来回调Main活动:

setResult(RESULT_OK, data);
finish();

I would have received the requestCode (25), the resultCode (RESULT_OK) and the data on onActivityResult if I didn't kill the process. However in this case I'm taken to the Main activity, but the onActivityResult is not called.

如果我没有杀死进程,我会收到requestCode(25),resultCode(RESULT_OK)和onActivityResult上的数据。但是在这种情况下,我被带到Main活动,但是没有调用onActivityResult。

Is this how Android works (which I don't expect), or is there something wrong with my approach?

这是Android的工作方式(我不指望),或者我的方法有问题吗?


Update: This happened on my Nexus One, CyanogenMod 7.0.2, Android 2.3.3. I tried using emulator API 10, Android 2.3.4 and it worked as expected, onActivityResult is still called after I killed the process.

更新:这发生在我的Nexus One,CyanogenMod 7.0.2,Android 2.3.3上。我尝试使用模拟器API 10,Android 2.3.4并且它按预期工作,onActivityResult在我杀死进程后仍然被调用。

2 个解决方案

#1


0  

I think the question is not why onActivityResult is not called, but why when you kill your app second is still alive. Did you put Toast messages in the lifecycle methods of Main and Sub, just to check which methods are called?

我认为问题不在于为什么没有调用onActivityResult,而是为什么当你杀死你的应用程序时,第二个仍然存在。您是否在Main和Sub的生命周期方法中放置了Toast消息,只是为了检查调用哪些方法?

#2


0  

I was facing the same problem and I solved it replacing the startActivityForResult functionality storing the result into the shared preferences and loading them later in onResume. Here's the link to the full solution.

我遇到了同样的问题,我解决了它取代了将结果存储到共享首选项中的startActivityForResult功能,并稍后在onResume中加载它们。这是完整解决方案的链接。

#1


0  

I think the question is not why onActivityResult is not called, but why when you kill your app second is still alive. Did you put Toast messages in the lifecycle methods of Main and Sub, just to check which methods are called?

我认为问题不在于为什么没有调用onActivityResult,而是为什么当你杀死你的应用程序时,第二个仍然存在。您是否在Main和Sub的生命周期方法中放置了Toast消息,只是为了检查调用哪些方法?

#2


0  

I was facing the same problem and I solved it replacing the startActivityForResult functionality storing the result into the shared preferences and loading them later in onResume. Here's the link to the full solution.

我遇到了同样的问题,我解决了它取代了将结果存储到共享首选项中的startActivityForResult功能,并稍后在onResume中加载它们。这是完整解决方案的链接。