Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.app;
- import androidx.appcompat.app.AppCompatActivity;
- import android.content.SharedPreferences;
- import android.os.Bundle;
- import android.widget.EditText;
- public class MainActivity extends AppCompatActivity {
- EditText n1,a1;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- n1=findViewById(R.id.n1);
- a1=findViewById(R.id.a1);
- }
- @Override
- protected void onResume() {
- super.onResume();
- SharedPreferences sh1 = getSharedPreferences(" MysharedPre",MODE_PRIVATE);
- String s1= sh1.getString("user","");
- int a2= sh1.getInt("age",0);
- n1.setText(s1);
- a1.setText(String.valueOf(a2));
- }
- @Override
- protected void onPause() {
- super.onPause();
- SharedPreferences sh = getSharedPreferences(" MysharedPre",MODE_PRIVATE);
- SharedPreferences.Editor MyEdit = sh.edit();
- MyEdit.putString("user ",n1.getText().toString());
- MyEdit.putInt("age",Integer.parseInt(a1.getText().toString()));
- MyEdit.commit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement