I have Activities A, B, and C. A starts B and C, one after the other. The problem is that B is opened, then C starts and covers B. I want A to wait until B has finished and returned, but that is not happening. C starts immediately after starting B, so the user never sees B.
I am using startActivityForResult() as suggested in other posts, but that is not helping.
Here is the code in Activity A:
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
if (! pm.isIgnoringBatteryOptimizations(getApplicationContext().getPackageName())) {
startActivityForResult(new Intent(android.provider.Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS), 1);
}
...
startActivity(new Intent(InitActivity.this, MyAwesomeActivity.class));
You have to chain the activities using
onActivityResult()
.A calls B, then in
onActivityResult()
you use the resultCode parameter to verify that B is returning. Once verified that you are in the callback from B, then you call C. So it's more like A starts B, then B starts C.