Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Intent-flags for PreferenceScreen in xml

My PreferencesActivity's view is populated through XML and in that XML I included a PreferencesScreen to navigate to the system's sync-preferences. It works fine using the code below.

My problem/question is, that when I opened the Sync-Preferences, open the home-screen and then open my App again, the Sync-Settings are opened, because they lie on top of the stack. Is there a possibility to include the NEW_TASK-flag in the xml to tell the screen that it's a new task and not associated with my App's stack?

<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>
like image 707
dst Avatar asked May 24 '11 10:05

dst


1 Answers

You can set android:launchMode="singleInstance". In your code example this would be:

    <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>

A "singleInstance" activity, on the other hand, permits no other activities to be part of its task. It's the only activity in the task. If it starts another activity, that activity is assigned to a different task — as if FLAG_ACTIVITY_NEW_TASK was in the intent.

You can read more here: http://developer.android.com/guide/topics/manifest/activity-element.html#lmode

like image 129
mcia Avatar answered Sep 30 '22 18:09

mcia