Reputation: 41470
I have two activities A and B. A launches activity B. In activity B I call setResult(RESULT_OK, intent) in a button click handler without calling finish() - which is the desirable behavior.
After rotating B and pressing back, A's onActivityResult receives RESULT_CANCELED for resultCode, rather than RESULT_OK.
I know this is caused by the fact that activity B was destroyed upon rotation. What's the common practice to make sure the correct result code is returned from B?
My initial thought is to save up mResultCode in onSaveInstanceState.
Upvotes: 1
Views: 890
Reputation: 3316
Save result in onSaveInstanceState and set the result again in onRestoreInstanceState method.
onRestoreInstanceState :
This method is called after onStart() when the activity is being re-initialized from a previously saved state, given here in savedInstanceState. Most implementations will simply use onCreate(Bundle) to restore their state, but it is sometimes convenient to do it here after all of the initialization has been done or to allow subclasses to decide whether to use your default implementation. The default implementation of this method performs a restore of any view state that had previously been frozen by onSaveInstanceState(Bundle).
This method is called between onStart() and onPostCreate(Bundle).
Upvotes: 1