Writing to a file errors – Android Studio

Well… In android you should save the info in a DB or use SharedPreferences. Its really simple:

SharedPreferences sp = getSharedPreferences(SHARED_PREF, getApplicationContext().MODE_PRIVATE);
Editor editor = sp.edit();
editor.putString(SP_NAME, etName.getText().toString());

And if you want to recover the information:

SharedPreferences sp = getSharedPreferences(SHARED_PREF,getApplicationContext().MODE_PRIVATE);
String cadName = sp.getString(SP_NAME, "");

if (cadName.length()>0){
Log.d("HELENA","info saved : "+cadName);
Log.d("HELENA","No info saved.");

Browse More Popular Posts

Leave a Comment