I have two activities, a Splash Activity (which starts up when the launcher icon is clicked), and a Map activity (which is started up later by an intent after the user logs in).
Sometimes when Map Activity is open, I go to the home screen, then try to resume the app where I left off a couple of seconds later. I have noticed that when I click on the launcher icon on the home screen to resume the current activity (Map Activity), I am instead re-directed to Splash activity. This goes against the behavior that is listed in the Android documentation.
According to the documentation: "When the user leaves a task by pressing the Home button, the current activity is stopped and its task goes into the background. The system retains the state of every activity in the task. If the user later resumes the task by selecting the launcher icon that began the task, the task comes to the foreground and resumes the activity at the top of the stack.”
When map activity is running, my back stack is:
---MapActivity (front-facing activity)
---SplashActivity
When I click home, I see onStop() being called in MapActivity (as expected), but when I click on the launcher activity, MapActivity is then destroyed and onNewIntent is called in SplashActivity. Does anyone know what is causing this behavior?
My Android Manifest is:
<activity
android:name=".SplashActivity"
android:exported="true"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="com.deca.mw.SplashActivity" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity
android:name=".activity.MapActivity"
android:hardwareAccelerated="true"
android:launchMode="singleTask" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
</activity>
And the intent to start MapActivity is:
Intent intent = new Intent(appContext, MapActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
appContext.startActivity(intent);
It's the android:launchMode="singleTask"
setting in your Android manifest. Try removing it and see if this corrects the problem you are describing.