0

I have activities flow:

+--+   +--+   +----+
|A1|-->|A2|-->|Home|
+--+   +--+   +----+

BACK button in A1 and Home should close the app. So I call finish() on A1 when A2 is started and also on A2 when Home is started (thanks to that A1 and A2 are never kept on back stack).

However, BACK button in A2 should lead to A1 so I override in A2 (A1 is already finished as stated above so I have to start it again)

@Override
public void onBackPressed() {
    final Intent intent = new Intent(getApplicationContext(), A1.class);
    startActivity(intent);
    finish();
}

Now, it's possible to start again with button in Home the sequence

Home (button pressed)->A1->A2->(return to Home)

In this case (i.e. when A1->A2 is started after Home) layout of A1 should be a little bit different.

4

1 に答える 1