October 25, 2024
Chicago 12, Melborne City, USA
Android

Android Launcher activity and the launch mode


I recently migrated to use Android 12’s new SplashScreen API and removed the custom splashactivity. The MainActivity always had launchMode = singleTask to avoid recreating it multiple times when deeplinking etc. This is also the recommended launchMode as per Android documentation.

I referred to this and this which conflicts with the actual documentation.

Here’s my original manifest:

<activity
    android:name=".MainActivity"
    android:launchMode="singleTask"
    android:screenOrientation="portrait"
    android:theme="@style/AppTheme"
    android:windowSoftInputMode="adjustPan">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

With this manifest, if I open any other activity, press Home and open the app again through app launcher, the navigation will reset back to MainActivity (expected, because of the launchMode). My question is why is this a recommended way but at the same time no provision to maintain the back stack?

If I remove the launchMode (defaults to standard), I do see activity’s onCreate getting called every time I launch it from Launcher, which shows the Splash again — this is not desirable. Am I missing anything?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video