Android 在xml中为PreferenceScreen设置意图标志

Android 在xml中为PreferenceScreen设置意图标志,android,android-activity,preferences,android-preferences,preferenceactivity,Android,Android Activity,Preferences,Android Preferences,Preferenceactivity,我的PreferencesActivity视图是通过XML填充的,在该XML中我包含了一个PreferencesScreen,用于导航到系统的同步首选项。 使用下面的代码可以很好地工作 我的问题是,当我打开同步首选项,打开主屏幕,然后再次打开我的应用程序时,同步设置被打开,因为它们位于堆栈的顶部。 是否有可能在xml中包含NEW_TASK-flag来告诉屏幕这是一个新任务,并且与我的应用程序堆栈没有关联 <PreferenceScreen android:title="@s

我的
PreferencesActivity
视图是通过XML填充的,在该XML中我包含了一个
PreferencesScreen
,用于导航到系统的同步首选项。 使用下面的代码可以很好地工作

我的问题是,当我打开同步首选项,打开主屏幕,然后再次打开我的应用程序时,同步设置被打开,因为它们位于堆栈的顶部。 是否有可能在xml中包含NEW_TASK-flag来告诉屏幕这是一个新任务,并且与我的应用程序堆栈没有关联

<PreferenceScreen
        android:title="@string/preferences_activity_syncaccounts_title"
        android:summary="@string/preferences_activity_syncaccounts_summary"
        android:dialogTitle="@string/preferences_activity_syncaccounts_title">
        <intent
            android:action="android.settings.SYNC_SETTINGS"/>
    </PreferenceScreen>

您可以设置android:launchMode=“singleInstance”。 在您的代码示例中,这将是:

    <PreferenceScreen
        android:title="@string/preferences_activity_syncaccounts_title"
        android:summary="@string/preferences_activity_syncaccounts_summary"
        android:dialogTitle="@string/preferences_activity_syncaccounts_title">
    <intent
        android:action="android.settings.SYNC_SETTINGS"
        android:launchMode="singleInstance" />
    </PreferenceScreen>

另一方面,“单实例”活动不允许其他活动成为其任务的一部分。这是任务中唯一的活动。如果它启动了另一个活动,则该活动将被分配给另一个任务-就好像FLAG_activity_NEW_task在意图中一样

您可以在此处阅读更多内容: