Getting activity result in OnPause after call to finish()
I'm looking for the accessor version of Activity's se开发者_如何学编程tResult(). Imagine getResult() to return a Bundle if a resultCode and Intent have been used in setResult().
The reason for this is by default activities load with the resultCode set to RESULT_CANCELED: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.3_r1/android/app/Activity.java#669, and I would like to be able to query the resultCode from the onPause method. This might save a listener for the back button pressed.
Can't you just save the resultCode
to a member variable when you set it and read it back in onPasuse
?
public class MyActivity extends Activity {
private int result = RESULT_CANCELLED;
...
// do some stuff
result = RESULT_OK;
setResult(result);
...
@Override
protected void onPause() {
super.onPause();
switch (result) {
case RESULT_OK:
// do stuff
break;
}
}
}
You could also do some something similar with any Intent
you use.
You would have to bear in mind that onPause
will be called any time that your Activity
is no longer in the foreground, not just when you have set a result and called finish()
.
精彩评论