I have some problem with my android project! I have created a preferences intent and it works fine in the emulator. but when I transfer the project and launch the preferences through the menu key of the mobile, it stops working and closes! I want to know what is going on with it!
My device is : Xperia Mini Pro –> Running Android ICS 4.0.4
the code is,
Preference class :
package com.sliit.droidman.main;
import com.sliit.droidman.R;
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class Prefs extends PreferenceActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.prefs);
}
}
Preference xml file :
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<EditTextPreference
android:title="Edit text"
android:key="name"
android:summary="enter your name"
></EditTextPreference>
<CheckBoxPreference
android:title="Music"
android:defaultValue="true"
android:key="checkbox"
android:summary="check this box"
></CheckBoxPreference>
<ListPreference
android:title="list"
android:key="list"
android:summary="this is a list to choose from"
android:entries="@array/list"
android:entryValues="@array/lValues"
></ListPreference>
</PreferenceScreen>
Place where the preferences is called into action :
SharedPreferences getprefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
boolean music = getprefs.getBoolean("checkbox", true);
if (music == true) {
splashmp3.start();
}
what Am I doing wrong here! I dont have any issue with the emulator! but the problem exists with the device! As I had a previous application developed in the same manner, I ran it in the device and it worked fine on the preferences. but this force closes. Do I have to give any permissions! O.o
I found out what was giving the error. it was an error where I create the prefs intent in a switch case. 🙂 I have mistyped the class name. so I corrected it and now it works like magic!