Here's the way I did it in my app: ActivityA is the first one to start; it in turn starts ActivityB. In ActivityB I may encounter an error, in which case I Want to return to activityA, or everything may finish correctly, in which case I want to "finish" the app altogether.
In ActivityA:
public class ActivityA extends Activity {
...
private final static int REQUEST_ACT_B = 1;
...
private void startChild() {
startActivityForResult(new Intent(this, ActivityB.class), REQUEST_ACT_B;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == REQUEST_TASK && resultCode == ActivityB.RESULT_OK) {
this.finish();
}
}
}
And then in ActivityB:
public class ActivityB extends Activity {
...
public final static int RESULT_OK = 1;
public final static int RESULT_ERROR = 2;
...
private void finishWithError() {
setResult(RESULT_ERROR);
finish();
}
private void finishSuccessfully() {
setResult(RESULT_OK);
}
}
Essentially, ActivityA starts ActivityB and expects a result back. If it receives back result "OK", then it closes itself and the user is none the wiser: the app has finished. If it received result "error", then ActivityA stays open.