Preference Manager and Shared Preferences
<p>I'm not sure what I'm doing wrong here and would appreciate some help please.</p>

<p>In the onCreate method of my main activity I have this:</p>

<pre><code>    // set the default preferences
    PreferenceManager.setDefaultValues(context, R.xml.preferences, false);

    // get the preferences
    prefs = getPreferences(MODE_PRIVATE);

    // Load the values or defaults from the SharedPreferences
    msMainClockStart = prefs.getLong( "Main_Clock_Minutes", 0 );
    useShotClock = prefs.getBoolean( "Use_ShotClock", false );
    msShotClockStart = prefs.getLong( "Shot_Clock_Seconds", 20000 );
    tvPeriodPrefix = prefs.getString( "Period_Prefix", "P" );
    valMaxPeriods = prefs.getInt( "Max_Periods", 4 );
</code></pre>

<p>In my res/xml/preferences.xml file I have the following</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;

&lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" &gt;
&lt;EditTextPreference
    android:key="Main_Clock_Minutes"
    android:positiveButtonText="SAVE" 
    android:negativeButtonText="CANCEL" 
    android:title="Main Clock (minutes)" 
    android:defaultValue="480000" 
    android:summary="How many minutes for the main clock."/&gt;

&lt;CheckBoxPreference 
    android:key="Use_ShotClock"
    android:title="Enable Shot Clock"
    android:defaultValue="true"/&gt;

&lt;EditTextPreference 
    android:key="Shot_Clock_Seconds"
    android:title="Shot Clock (seconds)" 
    android:summary="How many seconds for the shot clock." 
    android:defaultValue="30000"/&gt;

&lt;EditTextPreference 
    android:key="Period_Prefix"
    android:title="Period Prefix (e.g. Q, Shift, Period)" 
    android:defaultValue="Q"/&gt;

&lt;EditTextPreference 
    android:key="Max_Periods"
    android:title="Maximum number of periods" 
    android:defaultValue="4"/&gt;
</code></pre>

<p></p>

<p>For some reason the defaults are not getting read/loaded from the xml file.  The defaults that are entered in the getLong() method or getBool() method that are being used.</p>

<p>Does anyone know why?</p>

<p>EDIT @Gunnar Karlsson</p>

<p>After changing to <code>getDefaultSharedPreferences</code> I'm getting an error at line 121 which is this one:</p>

<pre><code>msMainClockStart = prefs.getLong( "Main_Clock_Minutes", 0 );
</code></pre>

<p>The Error says "cannot cast from a long to a string.  But msMainClockStart is a Long and prefs.getLong() returns a Long so I'm not sure why it doesn't work.</p>
