tags:

views:

45

answers:

2

I have 2 activities. In child activity i have put something like that in onPause():

if (isFinishing()) {
 final Intent intent = new Intent();
 intent.putExtra(SOME_DATA, value);

 setResult(RESULT_OK, intent);
 Log.i("test", "Result set to RESULT_OK");
}

In parent activity i check resultCode when child activity is destroyed, and this is what i have noticed:

  1. If i destroy child activity by some action (in some condition i invoke finish()), then resultCode is RESULT_OK
  2. But when i destroy by pressing return key (i works only in emulator so its ESC) who kills activity, then resultCode read in parent onActivityResult method equals 0 (RESULT_CANCELD).

"test" log read in each case is the same.

A: 

Most likely the thing that is destroying your activity resets the result after onPause is called to RESULT_CANCELED. This makes sense, since the activity did not finish happily.

What are you trying to accomplish by always setting the result code to RESULT_OK?

Mayra
Oh, i forget about this question.It is not really helpful, however your answer is most likely explanation of problem, so i'll accept your answer.And how i resolve problem: SharedPreferences ;)
Fisher
A: 

You don't have to set the result code in the onPause method. You could set it the moment you get the data. Just set the result code every time the data you want to pass back to your first activity changes and it should then get back to the calling activity in the correct way.

Janusz