title: Add sharedPreferences to listpreference values
body: <p>I have app starting with Splash screen then go to MainActivity depend on user preference which determined by chose any option in listpreference  :</p>
  
  <p>1- start app without splash and music .</p>
  
  <p>2- start app with splash only .</p>
  
  <p>3- start app with splash and music .</p>
  
  <p>i implement the listpreference but i cant add sharedPreferences to each values so after check any of them it stored in  sharedPreferences and start app depend on user preference,</p>
  
  <p>as this is first time to use listpreference and im new to android  i don't know how to do it,</p>
  
  <p>any help please will be appreciated .</p>
  
  <p><strong>Splash.java</strong></p>
  
  <pre><code> public class Splash extends Activity{  
  MediaPlayer ourSong;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
           setContentView(R.layout.splash);  
  
      ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound);     
      ourSong.start();
  
      Thread timer = new Thread(){
          public void run(){
              try{
                  sleep(2000); 
                  }
                catch (InterruptedException e){
                  e.printStackTrace(); 
                  }
                finally{
                    Intent intent = new Intent(Splash.this, MainActivity.class);                                     
                    startActivity(intent); 
                    }
              }                                   
          };
           timer.start();   
           }  
  @Override
  protected void onPause() {
              // TODO Auto-generated method stub
      super.onPause();
      ourSong.release();
      finish();
            } 
         }
  </code></pre>
  
  <p><strong>Prefs.java</strong></p>
  
  <pre><code>public class Prefs extends PreferenceActivity{
  
  @SuppressWarnings("deprecation")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
  
      addPreferencesFromResource(R.xml.prefs); 
      }
  }
  </code></pre>
  
  <p><strong>prefs.xml</strong></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;ListPreference
         android:title="Application Start Preference"
         android:summary="This preference allows to select how the app will start"
         android:key="listPref"
         android:entries="@array/splash"
         android:entryValues="@array/splash_values" /&gt;          
  &lt;/PreferenceScreen&gt;
  </code></pre>
  
  <p><strong>arrays.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
   &lt;resources&gt;   
    &lt;string-array name="splash"&gt;
        &lt;item&gt;start app without splash screen &lt;/item&gt;
        &lt;item&gt;start app with splash scrren only&lt;/item&gt;
        &lt;item&gt;start app with splash screen and music&lt;/item&gt;
    &lt;/string-array&gt;
  
    &lt;string-array name="splash_values"&gt;
        &lt;item&gt;1&lt;/item&gt;
        &lt;item&gt;2&lt;/item&gt;
        &lt;item&gt;3&lt;/item&gt;
  
    &lt;/string-array&gt;    
  &lt;/resources&gt;
  </code></pre>
  
  <p><strong>UPDATE:</strong>
  i tried the below code but whats happen is app run normally start with splash then go to mainactivity then i press preference in option menu its OK it open preference page then press on listpreference it rise the dialog of 3 radiobutton and if i press any one of radiobuttons its ok , then i back and back till exit app , then open it again it open directly to show the mainactivity without splash then crashes immediately.</p>
  
  <p>also line 23 in logcat is:</p>
  
  <pre><code> int splashType = getPrefs.getInt("listPref", 0);
  </code></pre>
  
  <p><strong>Splash.java</strong></p>
  
  <pre><code>public class Splash extends Activity{  
   MediaPlayer ourSong;
   @Override
    protected void onCreate(Bundle savedInstanceState) {
     this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);  
  
       SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences
               (getBaseContext());
  
   int splashType = getPrefs.getInt("listPref", 0);
    switch (splashType) {
    case 2:
  Intent intent = new Intent(Splash.this, MainActivity.class);                                     
         startActivity(intent);
    break;
  
    case 1:
     setContentView(R.layout.splash);  
      Thread timer = new Thread()
     {
      public void run()
      {
          try
          {
              sleep(2000); 
          }
          catch (InterruptedException e)
          {
              e.printStackTrace(); 
          }
          finally
          {
              Intent intent = new Intent(Splash.this, MainActivity.class);                                     
              startActivity(intent);  
           }
        }                          
      };
     timer.start();       
  break;
  
   case 0:
     ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound); 
     ourSong.start();
  
  Thread timer1 = new Thread(){
      public void run(){
          try{
              sleep(2000); }
            catch (InterruptedException e){
              e.printStackTrace(); }
            finally{
            Intent intent = new Intent(Splash.this, MainActivity.class);                                     
                  startActivity(intent); 
                      }
                     }                                    
                   };
             timer1.start();   
    break;
     }
    }
  @Override
  protected void onPause() {
       // TODO Auto-generated method stub
      super.onPause();
      ourSong.release();
      finish();
        } 
     }
  </code></pre>
  
  <p><strong>LOGCAT:</strong></p>
  
  <pre><code> java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tsn.dr/com.tsn.dr.Splash}: java.lang.ClassCastException: java.lang.String
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:130)
  at android.app.ActivityThread.main(ActivityThread.java:3687)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:507)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
  at dalvik.system.NativeStart.main(Native Method)
   Caused by: java.lang.ClassCastException: java.lang.String
  at android.app.ContextImpl$SharedPreferencesImpl.getInt(ContextImpl.java:2968)
  at com.tsn.dr.Splash.onCreate(Splash.java:23)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
  </code></pre>