I want to prevent user from leaving my app. I am trying to achieve this through home launcher activity/application and I don't understand android's behaviour. Pressing HOME first time always creates new activity in new task instead of moving the existing one to the foreground. When pressing HOME second time etc, nothing happens. See example:
I have a Login activity (A) and Settings activity (B). B is opened from A. A is set to be a launcher (LAUNCHER, DEFAULT, HOME categories).
- A opens B
- task T1: A -> B
- HOME
- another A is created into a new task (why?):
- T1: A -> B
- T2: A
- A opens B (task T2)
- T1: A -> B
- T2: A -> B
- HOME
- nothing happens, why?
I get the same behaviour when A's launchMode is either singleTop, singleTask or standard. With singleInstance there is only one A, but the B gets alone in T1 and I don't want that.
Why there is always a new task created? All intents flags have always the FLAG_ACTIVITY_NEW_TASK flag set. Why does android do that?
Is it the same behaviour as posted here or here? I can't use that solution because android creates a new task so A will always be the root. (or how can I check that this is a second instance?)
I can't use singleInstance as posted here, because I don't want B to be alone (if A is visible, it is also the only activity and task (login purposes)). I tried to remove all other tasks through ActivityManager but getAppTasks()
is for SDK >= 21, my min is 16.
I can't even use this solution because I never get intent with FLAG_ACTIVITY_BROUGHT_TO_FRONT flag. There is always FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag.
I've tried a lot of combinations with launchMode, clearTaskOnLaunch, noHistory, ... but nothing successful - always new task.
Any idea how to solve this? Running on Lollipop. Thank you.