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
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.
I found an easy one line solution for this problem
add this line in activity tag in Manifest
android:launchMode="singleInstance"
Use android:launchMode="singleInstance" instead
In your AndroidManifest, in the activity tag, just add
android:alwaysRetainTaskState="true"
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
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.