0

I have a activity A with launchMode=singleTop. And activity B with standart launch mode.

First case: I launching app from installer or Google Play (not from launcher), then start other activity B from activity A (after task stack will be A -> B (top of stack)). If i minimize the app and open app from launcher then activity A start to top of app stack (A -> B -> A).

Other case (right case): if i started app from launcher (not google play) then start activity B, minimize app and open app from laucner, then app restores previous state (stack: A -> B).

Is it able to prevent launching activity A to the top of stack in first case?

Pavel Santaev
  • 845
  • 7
  • 17

1 Answers1

1

I experienced this problem in my current project (About 2/3 weeks ago). Its not a problem with your stack. When application is launched from the installer/Google Play and then minimize it, go to launcher the app will add the launch activity to the top of the stack. This occurred only in some devices. After you kill the app once, it starts to work fine.

The work around was to check on App Start if the activity was launched from Launcher. I found this answer which had the exact workaround I thought of:

    if (!isTaskRoot()
            && getIntent().hasCategory(Intent.CATEGORY_LAUNCHER)
            && getIntent().getAction() != null
            && getIntent().getAction().equals(Intent.ACTION_MAIN)) {

        finish();
        return;
    }

Zohaib Amir
  • 3,482
  • 2
  • 11
  • 29
  • > This occurred only in test devices I had but worked fine on my personal device. @Zohaib What you do you mean by test device? This problem appears on my real device. – Pavel Santaev Jul 31 '19 at 10:17
  • 1
    @PavelSantaev It seems I made a confusing statement, What I meant was that it wasn't happening in my personal Redmi device but it occured on both OnePlus and Samsung test devices we have in company. – Zohaib Amir Jul 31 '19 at 10:19