Issue
Let's say I have Activity A. I start Activity B from Activity A using startActivityForResult(), and whenever that's done, the setResult() fuction is called in Activity B, resulting in Activity's A onActivityResult() being called.
But what if while I'm in Activity B, the android OS kills the app and restarts it. When the app is restored, I'm back in Activity B and I then choose to return back to Activity A by calling setResult(). So my question is, is Activity A's view recreated(onCreate() called) before its onActivityResult() is called? In such a scenario, is Activity A's onActivityResult() even called?
Thanks for reading.
Solution
So my question is, is Activity A's view recreated(onCreate() called) before its onActivityResult() is called? In such a scenario, is Activity A's onActivityResult() even called?
Yes. If OS has killed the process of your app and Activity B is finished, the OS knows to recreate Activity A and deliver the result to onActivityResult(), just as if Activity A hadn’t died at all.
Note:
- This is only possible if both of your activities are in different process. OS never kills activity directly when its under memory pressure. It simply kills the entire process hosting the activity. If both of your activities are hosted in same process then your scenario shouldn't happen.
- Any callback class instances, member variables, and even static variables are destroyed along with Activity A, since whole process is killed.You have to re-create them in Activity A.
Answered By - Sagar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.