Advertisement
zihadrizkyef

LoadData-SharedPreference

Jun 20th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. package zihadrizkyef.learn.sharedpreferences;
  2.  
  3. import android.content.Context;
  4. import android.content.SharedPreferences;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.widget.Button;
  8.  
  9. import android.widget.TextView;
  10. public class LoadData extends AppCompatActivity{
  11.     TextView tvName, tvAge, tvEmail;
  12.     Button bBack;
  13.  
  14.     @Override
  15.     protected void onCreate(Bundle savedInstanceState) {
  16.         super.onCreate(savedInstanceState);
  17.         setContentView(R.layout.activity_load_data);
  18.  
  19.         tvName = (TextView) findViewById(R.id.tvName);
  20.         tvAge = (TextView) findViewById(R.id.tvAge);
  21.         tvEmail = (TextView) findViewById(R.id.tvEmail);
  22.         bBack = (Button) findViewById(R.id.bBack);
  23.  
  24.         SharedPreferences sharedPreferences = getSharedPreferences("test.sp", Context.MODE_PRIVATE);
  25.         tvName.setText("Name : "+sharedPreferences.getString("key", "''"));
  26.         tvAge.setText("Age : "+sharedPreferences.getString("age", "''"));
  27.         tvEmail.setText("Email : "+sharedPreferences.getString("email", "''"));
  28. //        tvName.setText("Name : "+sharedPreferences.getString("name", "N/A"));
  29. //        tvAge.setText("Age : "+String.valueOf(sharedPreferences.getInt("age", 0)));
  30. //        tvEmail.setText("Email : "+sharedPreferences.getString("email", "N/A"));
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement