Question

I have an Activity A which starts an Activity B (Dialog Theme), where Activity A is then visible in the background and B in the foreground.

However, when pushing the home button and then returning to the app again, A is not visible any more - only B. onResume() of B is called, but not of A, which maybe is how it should be...

onDestroy() in A is not being called as I can see. What could be the reason for this behaviour?

A is defined as singleInstance MAIN/LAUNCHER Activity and starting B through SettingsActivity.show:

public static void show(final Context context, final boolean inRegisterFlow) {
    final Intent intent = new Intent(context, SettingsActivity.class);
    context.startActivity(intent);
}
Was it helpful?

Solution

The problem is your use of launchMode="singleInstance'. If ActivityA is defined with launchMode="singleInstance", then when ActivityA launches ActivityB, ActivityB ends up in a different task. When the user presses the BACK button, both tasks (the one containing ActivityA and the one containing ActivityB) end up in the background. When the user brings the task containing ActivityB to the foreground, the other task (containing ActivityA) is still in the background.

Your architecture sounds broken. Why are you launching a Dialog-themed Activity if you want it to behave like a Dialog? Why don't you just show a Dialog in ActivityA? Why are you using launchMode="singleInstance"? In general, this is wrong (unless you are developing a HOME-screen replacement) and it usually created more problems than it solves because most developers don't really understand how it works.

Also, onResume() is called on ActivityB because it is resumed (ie: it is in the foreground). onResume() isn't called on ActivityA because that activity isn't in the foreground. Only 1 activity is ever in "resumed state". All other activities are "paused".

OTHER TIPS

Maybe a quick fix apply here, add A.onResume() to be onResume() implementation, that is because when you come back A doesn't resume since its in background.

But that's just a bad approach

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top