Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8942411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:30:30+00:00 2026-06-15T11:30:30+00:00

I have a PreferenceActivity with several fragments: R.xml.preferences: (shortened for better readability): <?xml version=1.0

  • 0

I have a PreferenceActivity with several fragments:

R.xml.preferences: (shortened for better readability):

<?xml version="1.0" encoding="utf-8"?>
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android">
    <header android:fragment="fragments.Fragment1" android:id="@+id/fragment1" [...] />
    <header android:fragment="fragments.Fragment2" android:id="@+id/fragment2" [...] />
    [...]
</preference-headers>

SettingsActivity:

public class SettingsActivity extends PreferenceActivity {
    @Override
    public void onBuildHeaders(List<Header> target) {
        loadHeadersFromResource(R.xml.preferences, target);
    }
}

This will show a list entry with fragments.Fragment1, fragments.Fragment2, … if SettingsActivity is started.

But now I want to pass a Bundle such that a specific PreferenceFragment is opened when starting the activity:

so I added this to SettingsActivity:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null && savedInstanceState.getBoolean("shortcut")) {
        // directly jump to fragments.Fragment1
    }
}

I tried to load the fragment via getFragmentManager().findFragmentById(R.id.fragment1), but this returns null. But even if I had the correct instance, I would not know how to invoke it. Also, calling loadHeadersFromResource(R.xml.preferences_fragment1, target); does not work – This will throw a RuntimeException “XML document must start with tag; foundPreferenceScreen at Binary XML file“. I have no ideas left and also a search on SO and Google did not return any relevant results.

So my question is: Is it possible to directly load a PreferenceFragment (e.g. fragments.Fragment1) from the Activitiy’s onCreate method? If so, how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:30:31+00:00Added an answer on June 15, 2026 at 11:30 am

    According to:
    http://developer.android.com/reference/android/preference/PreferenceActivity.html#EXTRA_SHOW_FRAGMENT

    public static final String EXTRA_SHOW_FRAGMENT

    Added in API level 11 When starting this activity, the invoking Intent
    can contain this extra string to specify which fragment should be
    initially displayed.

    Constant Value: “:android:show_fragment”

    intent = new Intent( this, SettingsActivity.class );
    intent.putExtra( PreferenceActivity.EXTRA_SHOW_FRAGMENT, Fragment1.class.getName() );
    intent.putExtra( PreferenceActivity.EXTRA_NO_HEADERS, true );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have PreferenceActivity with some sample content: <?xml version=1.0 encoding=utf-8?> <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android> <PreferenceCategory android:title=First
I have the following code in my application in res/xml/preferences.xml: <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android> <PreferenceCategory android:title=Wi-Fi
I have a PreferenceActivity that loads two Fragments via the xml file for the
I have 1 PreferenceActivity in preferences.xml is <CheckBoxPreference android:id=@+id/pushCB android:checked=true android:defaultValue=true android:key=PushService android:summary=Set to
I have an activity which extends PreferenceActivity. I'm loading preferences from the xml file.
I have a PreferenceActivity that loads its preferences from an XML file which looks
In my extended PreferenceActivity class I call addPreferencesFromResource(R.xml.livewallpaper_settings) so I have a xml file
I have used PreferenceActivity to have preference in my android application. I want one
I have a settings class that extends PreferenceActivity. I have a checkbox preference in
I have a simple preference screen defined like this <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android> <PreferenceCategory android:title=Security> <CheckBoxPreference

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.