With what it seems like you're trying to do, you have two options: 1. Save state B when B is called onDestroy or onBackPressed. You will need to store this in memory or write it with some persistence (SharedPreferences, local file, etc.). Then, when B starts up, check if this data exists and if it uses state to load. 2. Override onBackPressed so that you do not call super.onBackPressed when pressed. Instead, start an instance of action A and set your goal flags FLAG_ACTIVITY_REORDER_TO_FRONT before calling startActivity. So something like this:
Intent intent = new Intent(this, A.class); intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(intent);
Now, when you click back, it should find instance A that is in your activity stack, and just bring it to the fore. You may need to add the same flag when starting B.
source share