启动模式不起作用
Launch Mode Does Not Work
我在我的清单文件中定义了启动模式,以便在后台堆栈上只保留一个 activity,但不幸的是,它没有解决后退导航问题。也就是说,用户必须反复单击返回导航按钮才能退出应用程序。这是我的清单配置。
<?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"/>
提前致谢
使用singleTask
或singleInstance
代替singleTop
在 Android 文档中:
标准和单顶
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 和 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.
来源:https://developer.android.com/guide/topics/manifest/activity-element.html
我在我的清单文件中定义了启动模式,以便在后台堆栈上只保留一个 activity,但不幸的是,它没有解决后退导航问题。也就是说,用户必须反复单击返回导航按钮才能退出应用程序。这是我的清单配置。
<?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"/>
提前致谢
使用singleTask
或singleInstance
代替singleTop
在 Android 文档中:
标准和单顶
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 和 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.
来源:https://developer.android.com/guide/topics/manifest/activity-element.html