Search code examples
androidlauncher

App is getting started again after launcher click even when it is already running


I have the problem that my App is starting again if the user clicks the launcher icon even if it is already running. I used singleTaks for that Activity and as many Stackoverflow Answers said -> This should solve the problem - but it doesnt.

<activity
    android:name=".activities.ActivitySplash"
    android:launchMode="singleTask">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

As you can see i did define the launchMode to be singleTask. I open the App. Navigate to Screen X (I even could stay on the Startscreen, has the same effect) and now i press the home button. When i now press the launcher icon again the already running app does not pop up or is getting resumed (call it as you wish). Instead the App is completly started new.

How can i prevent that behaviour, if singleTask isnt working?


Solution

  • Try with SingleTop:

    if the target task already has an existing instance of the activity at the top of its stack, that instance will receive the new intent (in an onNewIntent() call); a new instance is not created. In other circumstances — for example, if an existing instance of the "singleTop" activity is in the target task, but not at the top of the stack, or if it's at the top of a stack, but not in the target task — a new instance would be created and pushed on the stack.