Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.ted.android_sharedprefs;
- import android.content.Context;
- import android.content.SharedPreferences;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- public class ActivityTwo extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_activity_two);
- Button btnLoad = (Button) findViewById(R.id.btnLoad);
- final TextView tvUsername = (TextView) findViewById(R.id.tvUsername);
- final TextView tvPassword = (TextView) findViewById(R.id.tvPassword);
- assert btnLoad != null;
- btnLoad.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- SharedPreferences sp = getSharedPreferences("MyData", Context.MODE_PRIVATE);
- String musername = sp.getString("username", "no data retrieved");
- String mpassword = sp.getString("password", "no data retrieved");
- tvUsername.setText(musername);
- tvPassword.setText(mpassword);
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement