TL;DR My app gets minimized (as if the home-button was pushed) when I tap the navigation icon in my toolbar after going from an activity to another one and back.
Detailed flow of actions:
- Open app, Activity1 comes up
- Tap navigation icon (drawer opens normally, I can close and open it any amount of times at this stage, by pressing the navigation icon)
- Tap a drawer menu item which starts Activity2 with flag
FLAG_ACTIVITY_REORDER_TO_FRONT
- After Activity2 finishes loading, tap the navigation icon, drawer opens normally
- Tap the drawer menu item which starts Activity1 with the flag
FLAG_ACTIVITY_REORDER_TO_FRONT
(at this point this Activity exists so is brought to front) - After Activity1 is brought to front, tap navigation icon again to open the drawer
- Drawer starts sliding out from the left but app minimizes before it's out completely
I know the app is minimized because when I open it, Activity1 is on the screen with an open drawer
There's no Exception or log (level is at Verbose) and this happens only on a OnePlus Two (The app works fine on a Nexus 4)
In my case I need to switch between 2 distinct stack. I use
FLAG_ACTIVITY_REORDER_TO_FRONT
to handlestartActivity
andfinish()
.But I have the same problem like you, it get minimized in one case:
Activity Class A (instance 1) -> open new Activity Class A (instance 2) -> Activty Class B -> switch to Activity Class A (instance 2) by
FLAG_ACTIVITY_REORDER_TO_FRONT
, thenFLAG_ACTIVITY_REORDER_TO_FRONT
to back to (instance 1) will minimized (go to background), but if I make it foreground back it did finish(), it just go to background by unknown reason.It only happen if two class A instances on the stack continuously. I check the stack by
adb shell dumpsys window windows | grep 'Window #'
After I tried a lot of
FLAG
combination with no succeed, I come out with a hack idea, i.e. create aDistinct
activity class.While I already able to detect this is the same class on the stack (use
registerActivityLifecycleCallbacks
to push/pop the activity list stack), then when I want to back I simply call theDistinct
class and make itfinish()
immediately inonCreate()
. Then on thefinish()
code willFLAG_ACTIVITY_REORDER_TO_FRONT
the class A instance 1. Since the Distinct class is not the same class of A, then it able toFLAG_ACTIVITY_REORDER_TO_FRONT
the instance 1 and close instance 2 just fine.[UPDATE]
This answer actually buggy, but eventually I figure out the better way and write the answer here.