Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zihadrizkyef.learn.sharedpreferences;
- import android.content.Context;
- import android.content.SharedPreferences;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.widget.Button;
- import android.widget.TextView;
- public class LoadData extends AppCompatActivity{
- TextView tvName, tvAge, tvEmail;
- Button bBack;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_load_data);
- tvName = (TextView) findViewById(R.id.tvName);
- tvAge = (TextView) findViewById(R.id.tvAge);
- tvEmail = (TextView) findViewById(R.id.tvEmail);
- bBack = (Button) findViewById(R.id.bBack);
- SharedPreferences sharedPreferences = getSharedPreferences("test.sp", Context.MODE_PRIVATE);
- tvName.setText("Name : "+sharedPreferences.getString("key", "''"));
- tvAge.setText("Age : "+sharedPreferences.getString("age", "''"));
- tvEmail.setText("Email : "+sharedPreferences.getString("email", "''"));
- // tvName.setText("Name : "+sharedPreferences.getString("name", "N/A"));
- // tvAge.setText("Age : "+String.valueOf(sharedPreferences.getInt("age", 0)));
- // tvEmail.setText("Email : "+sharedPreferences.getString("email", "N/A"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement