Whenever I re-launch application from home screen it starts launcher activity specified in manifest but when I press back button then application does navigate to activity which was previously minimized by pressing home button:
home -> A -> B -> home -> A -> back -> B
Instead, I expect application should close activity A after pressing back button. Mentioned activities are specified in manifest file as follows:
<activity android:name="A"
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:noHistory="true"
<intent-filter>
<action android:name="android:intent.action.MAIN"/>
<category android:name="android:intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="B"
android:launchMode="singleTop"
</activity>
I need to clear the history of activity A whenever activity B is launched. This looks like clearTaskOnLaunch="true" does not work with noHistory="true" or when calling finish() manually on activity A. Additionally when either one of noHistory="true" or finish() are specified/called then it is necessary to have launchMode="singleTask" in manifest for activity A, otherwise activity B would be launched from home screen instead of activity A.
How can I clear activity B whenever activity A is launched? Adding finishOnTaskLaunch="true" to activity B in manifest does not help. Both activities do have default affinity. Compile sdk version is 26.