Reputation: 2796
I have ActivityA as launcher activity.
From ActivityA I open -> ActivityB. I put the app in background.
When I open the app from recents the app is resumed with ActivityB. When I open the app from homescreen, the app is resumed with ActivityA without calling onCreate(), just onResume().
Why is ActivityB cleared from stack when I open the app from homescreen, even if onCreate() from ActivityA is never called, and how to fix this?
Manifest file looks like this:
ActivityA:
<activity-alias
android:name=".Launcher"
android:label="@string/app_name"
android:targetActivity="path.ActivityA">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity
android:name=".path.ActivityA"
android:launchMode="singleTask"
android:screenOrientation="sensorPortrait"
android:theme="@style/BlackIntroTheme"
android:windowSoftInputMode="adjustPan">
<nav-graph android:value="@navigation/graph1" />
<nav-graph android:value="@navigation/graph2" />
<nav-graph android:value="@navigation/graph3" />
<nav-graph android:value="@navigation/graph4" />
</activity>
ActivityB:
<activity
android:name=".path.ActivityB"
android:launchMode="singleTask"
android:screenOrientation="sensorPortrait"
android:windowSoftInputMode="adjustPan" />
Upvotes: 2
Views: 356
Reputation: 19233
this is how Activity
stacking works, some nice example of all launchMode
s in HERE, more complex info in DOCs
in short - Activity
with singleTask
started (again) will clear all on-top-of-it Activities
. you have your first MAIN
Activity
declared with this launchMode
, so every icon click on devices launcher will clear your Activities
stack. you can track this by overriding onNewIntent
method. picking from recents just brings all your Activities
stack to front, with last opened on top ofc.
consider removing launchMode
(is this necessary line for you?) or set it as standard
(default)
android:launchMode="standard"
Upvotes: 5