2

I have two activities one is log in and other is logout when the user logs out I'm sending the email value to the login page and saving that value so the last user should not have to enter it again. The problem is when the user closes the app from the login in activity and reopens it the value of shared Preference is not getting loaded. my code sign-in activity: I'm getting the value from the log out of the act.

bundle    = getIntent().getExtras();
    if(bundle != null) {
        bundle = getIntent().getExtras();
        email  = bundle.getString("email");
        //Toast.makeText(this, ""+email, Toast.LENGTH_SHORT).show();
    }

saving it on onCreate: after getting the value

saveData();
public void saveData() {
            Email.setText(email);
            SharedPreferences sharedPref = getSharedPreferences("myFile", Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putString("email", email);
            editor.apply();
            //Toast.makeText(this, "saved", Toast.LENGTH_SHORT).show();
        }

loading it on onResume:

@Override
    public void onResume(){
        super.onResume();
        SharedPreferences sharedPref = getSharedPreferences("myFile", Context.MODE_PRIVATE);
        String text = sharedPref.getString("email", null);
        Email.setText(text);
    }
Tanveer Munir
  • 1,956
  • 1
  • 12
  • 27

0 Answers0