Let's say I have a simple app, with a SplashScreenActivity and a MainActivity.
Below is part of my AndroidManifest.xml:
<activity
android:name=".front.activities.splashscreen.SplashScreenActivity"
android:launchMode="standard"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".front.activities.main.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/Main_Title"
android:launchMode="singleTop"
android:screenOrientation="portrait"/>
And my SplashScreenActivity opens MainActivity in onCreate().
The Problem
If the app is launched from Google Play instead of launcher, if I pressed home and click the app icon in the launcher, one more SplashScreenActivity is launched again and therefore one more MainActivity on the backstack.
Steps to reproduce
- Kill the app if it is opened.
- Open the app from Google Play.
- Press Home button
- Open the app from launcher. You will know notice that
SplashScreenActivityhas been launched again (Or by looking at logs) - Repeat step 3-4. Each time you repeat, one more
SplashScreenActivityandMainActivityis launched.
After several trials, if we press back button, we will notice that there are multiple MainActivity in the back stack.
More information
- If the app is not started from Google Play, but from launcher at the very first time (step 2), this cannot be reproduced.
- Not only Google play, but any other app that sends an intent to start the app can reproduce this.
- If I first launch from launcher, and then from Google Play, 2
SplashScreenActivitywill be launched. But if I press app icon from launcher again, it will not create a 3rdSplashScreenActivity. It will bring the first launchedMainActivityto the top.
What have I tried
- Make
SplashScreenActivitytoandroid:launchMode="singleTask". Does not help. - Make
MainActivitytoandroid:launchMode="singleTask". This will prevent multipleMainActivityfrom being created, but does not solve the problem of startingSplashScreenActivitymultiple times. You may also assumeMainActivityshould not be set tosingleTask.
What I expected
By clicking on the app icon in the launcher, Android should be able to find out that in my task manager, the app is already launched and will simply bring it to the top.
How can I fix this?
from Google Play and Launcher launched separated activities
No comments:
Post a Comment