Reputation: 8768
The question title is possibly not clear enough. It addresses the problem of passing results from a child activity to a parent activity after the application has been "killed" by Android on low resources condition, and then automatically restored when a user returns to this application.
Suppose an activity A invokes an activity B using startActivityForResult()
. While the application execution context is in B, the application goes to background and after some time gets unloaded by the system. Later the user switches back to the application and the activity B is restored without a problem. The only problem is that A does not exist at the moment in Android's backstack, and when user closes B (finish()
accompanied with a proper setResult()
call), A does not receive results. Instead of onActivityResult()
event, A receives onCreate()
and other events from startup chain.
So the question is how to pass results between activities in an application being restored after "killed" state?
UPDATE:
Despite the fact that @fedepaol provided a link to google groups, where someone wrote that onActivityResult
should be called in the situation in question, I could not make it to work. I should also note that the OP of that question in google groups did not solve the problem as well. Also I found a similar question here on SO - onActivityResult is not called after process is killed - also without a solution.
I double checked my code and don't see why it does not work. In normal situation the overridden method is called. If the back stack of activities is restored one by one, it does not.
Upvotes: 0
Views: 321
Reputation: 6862
I am not sure that your onActivityResult
would not be called.
From my understanding (which may not be correct), the os should give you all the instruments to reconstruct the state of A with the onCreate
/ onRestoreInstanceState
methods. After them I expect onActivityResult to be called with the previous result.
This is also confirmed by this answer by Dianne Hackborn.
It is also true that you should be handle the case where B gets killed just before returning the result.
Upvotes: 1