Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. package com.example.app;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4.  
  5. import android.content.SharedPreferences;
  6. import android.os.Bundle;
  7. import android.widget.EditText;
  8.  
  9. public class MainActivity extends AppCompatActivity {
  10. EditText n1,a1;
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.activity_main);
  15.  
  16. n1=findViewById(R.id.n1);
  17. a1=findViewById(R.id.a1);
  18.  
  19. }
  20.  
  21. @Override
  22. protected void onResume() {
  23. super.onResume();
  24.  
  25. SharedPreferences sh1 = getSharedPreferences(" MysharedPre",MODE_PRIVATE);
  26. String s1= sh1.getString("user","");
  27. int a2= sh1.getInt("age",0);
  28. n1.setText(s1);
  29. a1.setText(String.valueOf(a2));
  30. }
  31.  
  32. @Override
  33. protected void onPause() {
  34. super.onPause();
  35. SharedPreferences sh = getSharedPreferences(" MysharedPre",MODE_PRIVATE);
  36. SharedPreferences.Editor MyEdit = sh.edit();
  37. MyEdit.putString("user ",n1.getText().toString());
  38. MyEdit.putInt("age",Integer.parseInt(a1.getText().toString()));
  39. MyEdit.commit();
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement