onActivityResult is not called after process is killed

99封情书 提交于 2019-12-22 08:51:39

问题


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

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.

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

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.

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


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.


回答1:


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?




回答2:


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.



来源:https://stackoverflow.com/questions/6328413/onactivityresult-is-not-called-after-process-is-killed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!