public class Calc extends Activity {
public static final String PREFS_NAME = "MyPrefsFile";
@Override
protected void onCreate(Bundle state){
super.onCreate(state);
. . .
// Restore preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
String ipAddress = settings.getString("IPAddress", "");
int port = settings.getInt("port", 0);
int title = settings.getString("Title", "");
}
@Override
protected void onStop(){
super.onStop();
// We need an Editor object to make preference changes.
// All objects are from android.context.Context
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("IPAddress", "127.0.0.1");
editor.putInt("port", 1234);
editor.putString("Title", "MyNewApplication");
// Commit the edits!
editor.commit();
}}