Reputation: 87
Im having a FC issue on my preference setup. I looked on the web for some preference examples to work for both API lower and higher than 3.0. So I got 2 xml preference files just like the tutorial. Then I used the same method to check and call each xml preference file and now getting FC. I also had to manually changed min API to 11 from 7 to run sometimes which defeat the purpose. Both xmls are identical. Any insight?
Prefs Class
package com.armstrong.yi.android.app;
import java.util.List;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import com.armstrong.yi.android.app.R;
public class Prefs extends PreferenceActivity {
final static String ACTION_PREFS_ONE = "com.armstrong.yi.android.app.PREFS";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
String action = getIntent().getAction();
if (action != null && action.equals(ACTION_PREFS_ONE)) {
addPreferencesFromResource(R.xml.prefs);
}
else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
// Load the legacy preferences headers
addPreferencesFromResource(R.xml.prefs_legacy);
}
}
public void onBuildHeaders(List<Header> target) {
loadHeadersFromResource(R.xml.prefs, target);
}
}
prefs xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<EditTextPreference
android:key="name"
android:summary="Enter Your Name"
android:title="EditText" />
<CheckBoxPreference
android:defaultValue="true"
android:key="checkbox"
android:summary="for the splash screen"
android:title="Music" />
<ListPreference
android:entries="@array/list"
android:key="list"
android:summary="This is a list to choose from"
android:title="list"
android:entryValues="@array/lValues" />
</PreferenceScreen>
Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.armstrong.yi.android.app"
android:versionCode="2"
android:versionName="2.7.9" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<application
android:name="GlobalVariables"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Splash"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.armstrong.yi.android.app.NumCounter"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="com.armstrong.yi.android.app.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Menu"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="com.armstrong.yi.android.app.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TextPlay"
android:label="@string/title_activity_main" >
</activity>
<activity
android:name=".Email"
android:label="@string/title_activity_main" >
</activity>
<activity
android:name=".DailyDataEntry"
android:label="@string/title_activity_main" >
</activity>
<activity
android:name=".WeeklyDataEntry"
android:label="@string/title_activity_main" >
</activity>
<activity
android:name=".Camera"
android:label="@string/title_activity_main"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".InitialDataEntry"
android:label="@string/title_activity_main" >
</activity>
<activity
android:name=".FinalDataEntry"
android:label="@string/title_activity_main" >
</activity>
<activity
android:name=".Rankings"
android:label="@string/title_activity_main" >
</activity>
<activity
android:name=".Data"
android:label="@string/title_activity_main" >
</activity>
<activity
android:name=".OpenedClass"
android:label="@string/title_activity_main" >
</activity>
<activity
android:name=".AboutUs"
android:label="@string/title_activity_main"
android:theme="@android:style/Theme.Dialog" >
<intent-filter>
<action android:name="com.armstrong.yi.android.app.ABOUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.armstrong.yi.android.app.GlobalVariables"
android:label="@string/title_activity_main" >
</activity>
<activity
android:name=".Prefs"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="com.armstrong.yi.android.app.PREFS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Error log
01-23 17:44:40.877: W/dalvikvm(2095): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
01-23 17:44:40.957: E/AndroidRuntime(2095): FATAL EXCEPTION: main
01-23 17:44:40.957: E/AndroidRuntime(2095): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.armstrong.yi.android.app/com.armstrong.yi.android.app.Prefs}: java.lang.RuntimeException: XML document must start with <preference-headers> tag; foundPreferenceScreen at Binary XML file line #2
01-23 17:44:40.957: E/AndroidRuntime(2095): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-23 17:44:40.957: E/AndroidRuntime(2095): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-23 17:44:40.957: E/AndroidRuntime(2095): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-23 17:44:40.957: E/AndroidRuntime(2095): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-23 17:44:40.957: E/AndroidRuntime(2095): at android.os.Handler.dispatchMessage(Handler.java:99)
01-23 17:44:40.957: E/AndroidRuntime(2095): at android.os.Looper.loop(Looper.java:137)
Upvotes: 3
Views: 1525
Reputation: 1431
I solved with:
Intent intent = new Intent(this, ActivityPreferences.class);
intent.putExtra(ActivityPreferences.EXTRA_NO_HEADERS, true );
intent.putExtra(ActivityPreferences.EXTRA_SHOW_FRAGMENT,FragmentPreferences.class.getName());
startActivity(intent);
Upvotes: 0
Reputation: 36449
You need to add another file, such as pref_headers.xml
since Android can also use headers to determine how to show the preferences. See the documentation.
In it, put the name of your Fragment
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android" >
<header
android:fragment="com.myapp.MyFragment"
android:title="My header" />
</preference-headers>
Add more header
tags for other fragments.
Then change
loadHeadersFromResource(R.xml.prefs, target);
to
loadHeadersFromResource(R.xml.pref_headers.xml, target);
Upvotes: 3