After Home button press re-launching app shows initial activity not current

后端 未结 6 1437
不知归路
不知归路 2021-01-04 04:12

I have an application that has an initial activity (A - also the one specified in the launcher) from which it allows the user to launch another activity (B). I am saving the

相关标签:
6条回答
  • 2021-01-04 04:40

    This answer is for someone coming from search engine due to similar kind of issue.

    I had,

    Launcher Activity -> A 
    Main Activity -> B
    

    Always starts A after pressing HOME button or Switching from task list when application was in B.

    Finally found that the problem was in manifest, removed

    android:noHistory = "true"

    from Activity declaration of B in manifest and it was resolved.

    0 讨论(0)
  • 2021-01-04 04:41

    I found an easy one line solution for this problem

    add this line in activity tag in Manifest

    android:launchMode="singleInstance"
    
    0 讨论(0)
  • 2021-01-04 04:43

    Use android:launchMode="singleInstance" instead

    0 讨论(0)
  • 2021-01-04 04:44

    In your AndroidManifest, in the activity tag, just add

    android:alwaysRetainTaskState="true"
    
    0 讨论(0)
  • 2021-01-04 04:45

    This is because another instance of app is launching when icon is pressed.

      // To prevent launching another instance of app by clicking app icon 
                    if (!isTaskRoot()
                            && getIntent().hasCategory(Intent.CATEGORY_LAUNCHER)
                            && getIntent().getAction() != null
                            && getIntent().getAction().equals(Intent.ACTION_MAIN)) {
    
                        finish();
                        return;
                    }
    

    write the above code in your launcher activity before calling setContentView. This will solve the problem

    0 讨论(0)
  • 2021-01-04 04:48

    Try adding this to your activity inside the manifest file:

    android:launchMode="singleTask"
    

    This resolved the issue in my app .... if I understand your problem correctly.

    0 讨论(0)
提交回复
热议问题