The answer is to override the child Activity's finish() method, to ensure that the setResult is called before the super.finish() method is called.
@Override
public void finish() {
if (doSaveOnPause()) {
if (save()) {
// Set the insert / edit action result to OK
mSuccessfullySaved = true;
}
}
if(mSuccessfullySaved) {
// Notify the caller Activity that the user successfully
// edited or inserted the data set
Intent _intent = new Intent("inline-data").setData(mUri);
Log.d(TAG,"Completing, with result="+RESULT_OK+", data="+_intent.getData().toString());
setResult(RESULT_OK,_intent);
}
else {
// Notify the caller Activity that the user has canceled the activity
// without altering anything
Log.d(TAG,"Completing, with result="+RESULT_CANCELED);
setResult(Activity.RESULT_CANCELED);
}
// Prevent onPause to re-save the record again during the close down of the activity.
mSuccessfullySaved = false;
super.finish();
}
No comments:
Post a Comment