title: Android SharedPreferences Issue - Get Data From Another Class
body: <p>I'm trying to pass data without using Intents so that certain classes can access the data.  So  what I decided to do is use SharedPreferences.  When I run the code I have a Toast in the End() method display the url I set in the Start() method.  The toast displays my default message but not the url I have stored in the SharedPreferences. </p>
  
  <p>Here is the code for the Start() method: </p>
  
  <pre><code>import java.net.URI;
  import java.net.URISyntaxException;
  
  import android.content.Intent;
  import android.content.SharedPreferences;
  import android.app.Activity;
  import android.widget.Toast;
  import android.net.Uri;
  import android.os.Bundle;
  
  public class Start extends Activity { 
  public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState);
      String uriStr = "http://www.google.com";
      URI uri = null;
  
      try {
          uri = new URI(uriStr);
      } catch (URISyntaxException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      String trackUri = uri.toString();
      SharedPreferences sharedPref = getSharedPreferences("FileName", MODE_PRIVATE); 
      SharedPreferences.Editor prefEditor = sharedPref.edit(); 
      prefEditor.putString("track_uri", trackUri);
      prefEditor.commit();
      Intent intent = new Intent(getBaseContext(), End.class);
      startActivity(intent);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Here is the code for the End() method: </p>
  
  <pre><code>import java.net.URI;
  import java.net.URISyntaxException;
  
  import android.content.Context;
  import android.content.SharedPreferences;
  import android.app.Activity;
  import android.widget.Toast;
  import android.net.Uri;
  import android.os.Bundle;
  import android.preference.PreferenceManager;
  
  public class End extends Activity { 
  private Context mContext;
  
  public End() { 
  }
  
  public End (Context context) { 
      mContext = context;
  }
  
  public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState);
      mContext = getApplicationContext();
      String trackUri = "Test";
      //SharedPreferences sharedPref = getSharedPreferences("FileName", MODE_PRIVATE); 
      SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mContext);
      sharedPref.getString("track_uri", trackUri);
      Toast.makeText(getApplicationContext(), trackUri, Toast.LENGTH_LONG).show();
  }
  }
  </code></pre>
  
  <p>Basically all I want to do is get data from another class without having to keep track of it and pass it using Intents when I can another class.</p>
  
  <p>What am I doing wrong? Any help is appreciated.</p>