Note that there are some explanatory texts on larger screens.

plurals
  1. POSharedpreference is not saving
    primarykey
    data
    text
    <p>i have a problem with my sharedpreferences, it is not working.</p> <p>I have strugled with this, for very long now and i'm so frustrated why this won't work.</p> <p>I have tried to put the load method in the Oncreate and also in the Onresume method none of them have worked.</p> <p>I want to save my: </p> <p>boolean value = stopValue, this should be false the first time i use the app, and in the future it should load from what have been saved last. The boolean value change when i use buttons in another class, therefore i have the getIntent().getBooleanExtra();</p> <p>String, called date.</p> <p>An Int, startkilometer.</p> <p>These are the data to be stored.</p> <p>Thanks for your time.</p> <p>But here is my code for my Main class:</p> <pre><code>public class Main extends Activity{ Button bStart, bStop; TextView tvView; Spinner spinner1; boolean stopValue; int startkilometer; String date; SharedPreferences prefs; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); bStart = (Button) findViewById(R.id.bStart); tvView = (TextView) findViewById(R.id.tvView); spinner1 = (Spinner) findViewById(R.id.spinner1); date = getIntent().getStringExtra("datoen"); startkilometer = getIntent().getIntExtra("startkm", startkilometer); stopValue = getIntent().getBooleanExtra("stopper", stopValue); if(stopValue == false){ bStart.setText("Start"); bStart.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub Intent start = new Intent("com.uniqueapps.runner.START"); startActivity(start); } }); } if(stopValue){ bStart.setText("Stop"); bStart.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent stop = new Intent("com.uniqueapps.runner.STOP"); stop.putExtra("startkm", startkilometer); stop.putExtra("datoen", date); startActivity(stop); } }); } KilometerSQL info = new KilometerSQL(this); info.open(); String data = info.getData(); info.close(); tvView.setText(data); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); prefs.getBoolean("stopper", false); prefs.getInt("startkm", startkilometer); prefs.getString("datoen", date); } @Override protected void onPause() { // TODO Auto-generated method stub Editor edit = prefs.edit(); edit.putBoolean("stopper", stopValue); edit.putInt("startkm", startkilometer); edit.putString("datoen", date); edit.commit(); super.onPause(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload