I have this small code snippet which accesses my preferences so that when my checkbox is 'true' then splash music plays. Otherwise it does not. The tutorial I am following works with this code, but mine does not. Can anyone see a problem with my code?
When I run the app, the music plays regardless but I don't get any errors.
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
ourSong = MediaPlayer.create(Splash.this, R.raw.clip1);
SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
boolean musicCheck = getPrefs.getBoolean("checkbox",true);
if (musicCheck == true){
ourSong.start();
}
Preferences XML:
<EditTextPreference
android:title="EditText"
android:key="name"
android:summary="Enter your name"/>
<CheckBoxPreference
android:title="Music"
android:defaultValue="True"
android:key="Checkbox"
android:summary="For the Splash Screen"/>
<ListPreference
android:title="List"
android:key="list"
android:summary="This is a list"
android:entries="@array/list"
android:entryValues="@array/lvalues"
></ListPreference>