Skip to content

Instantly share code, notes, and snippets.

@jobinjj
Created June 1, 2019 16:13
Show Gist options
  • Save jobinjj/e430f7d29c6cdb6d5529558d16394929 to your computer and use it in GitHub Desktop.
Save jobinjj/e430f7d29c6cdb6d5529558d16394929 to your computer and use it in GitHub Desktop.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_save = findViewById(R.id.btn_save);
btn_load = findViewById(R.id.btn_load);
btn_second = findViewById(R.id.btn_second);
ed_name = findViewById(R.id.ed1);
ed_email = findViewById(R.id.ed2);
//implementing onclick listener
btn_save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//getdata from edittext and store in corresponding string file
str_email = ed_email.getText().toString();
str_name = ed_name.getText().toString();
SharedPreferences sharedPreferences = getPreferences(Context.MODE_PRIVATE);
//we need editor to edit created shared preference file
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("name",str_name);
editor.putString("email",str_email);
editor.apply();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment