Arduino Uno

Header

Corner

SharedPreferences

Sometimes you need to save and load configuration settings. A simple way to achieve this is using the SharedPreferences object.

Load data from a file

SharedPreferences settings = getSharedPreferences("my.settings", 0);
((EditText)findViewById(R.id.serverEditText)).setText(settings.getString("server", ""));
((EditText)findViewById(R.id.emailEditText)).setText(settings.getString("email", ""));
((EditText)findViewById(R.id.usernameEditText)).setText(settings.getString("username", ""));
((EditText)findViewById(R.id.passwordEditText)).setText(settings.getString("password", ""));

Save data to a file

SharedPreferences settings = getSharedPreferences("my.settings", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("server", ((EditText)findViewById(R.id.serverEditText)).getText().toString());
editor.putString("email", ((EditText)findViewById(R.id.emailEditText)).getText().toString());
editor.putString("username", ((EditText)findViewById(R.id.usernameEditText)).getText().toString());
editor.putString("password", ((EditText)findViewById(R.id.passwordEditText)).getText().toString());
editor.commit();

 Official Storage Options developper page