narimetisaigopi

homeactivity.java sp

Feb 15th, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. package com.example.saigopinarimeti.helloworld;
  2.  
  3. import android.content.SharedPreferences;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.widget.TextView;
  7.  
  8. public class HomeActivity extends AppCompatActivity {
  9.  
  10. TextView textView;
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.activity_home);
  15.  
  16. textView = findViewById(R.id.text);
  17.  
  18. SharedPreferences sharedPreferences = getSharedPreferences("user",MODE_PRIVATE);
  19.  
  20. if (sharedPreferences!=null){
  21. String username = sharedPreferences.getString("username","sai");
  22. textView.setText("Logged in as "+username);
  23. }
  24.  
  25. }
  26. }
Add Comment
Please, Sign In to add comment