I have defined launch mode in my manifest file to keep only a single activity on the backstack but unfortunately, it does not fix the back navigation problem. That is the user has to click back navigation button repeatedly to exit the application. Here is my manifest configuration.
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@drawable/ic_action_launcher"
android:label="@string/app_name"
android:roundIcon="@drawable/ic_action_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:launchMode="singleTop"/>
<activity android:name=".DataViewActivity"
android:launchMode="singleTop"/>
<activity android:name=".FormsViewActivity"
android:launchMode="singleTop"/>
<activity android:name=".ProfileViewActivity"
android:launchMode="singleTop"/>
<activity android:name=".NotificationsActivity"
android:launchMode="singleTop"/>
<activity android:name=".NotificationViewActivity"
android:launchMode="singleTop"/>
<activity android:name=".LoginActivity"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".InitialSetupActivity"
android:launchMode="singleTop">
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
Thanks in advance
Use singleTask
or singleInstance
instead of singleTop
In Android Docs:
standard and singleTop
An activity with the "standard" or "singleTop" launch mode can be instantiated multiple times. The instances can belong to any task and can be located anywhere in the activity stack. Typically, they're launched into the task that called startActivity() (unless the Intent object contains a FLAG_ACTIVITY_NEW_TASK instruction, in which case a different task is chosen — see the taskAffinity attribute)
singleTask and singleInstance
In contrast, "singleTask" and "singleInstance" activities can only begin a task. They are always at the root of the activity stack. Moreover, the device can hold only one instance of the activity at a time — only one such task.
Source: https://developer.android.com/guide/topics/manifest/activity-element.html