Reputation: 3676
I'm trying to read my app preferences and I get this error:
Settings activity:
public class Settings extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
try
{
addPreferencesFromResource(R.xml.prefs);
}
catch (Exception ex)
{
Log.e("errorSettings", Log.getStackTraceString(ex));
}
}
}
Preferences XML File:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="General">
<SwitchPreference
android:title="Downloader"
android:defaultValue="true"
android:key="useDownloader"
android:summary="Enable to use" />
</PreferenceCategory>
</PreferenceScreen>
and on the application manifest I set this:
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="15" />
and the first error I get is:
android.view.InflateException: Binary XML file line #4: Error inflating class SwitchPreference
Thanx upfront.
Upvotes: 4
Views: 5180
Reputation: 1006759
SwitchPreference
was added in API Level 14. You cannot use it on earlier versions of Android. Since you are trying to support back to API Level 9, you can either:
Use different preference XML for earlier versions, using a CheckBoxPreference
instead of a SwitchPreference
, or
Just use CheckBoxPreference
and drop SwitchPreference
for now
Upvotes: 14