ZazoTazo

Shared Preferences After Login Page (Failed)

Jul 27th, 2019
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. package com.rcc.www.loginpage;
  2.  
  3. import android.content.Intent;
  4. import android.content.SharedPreferences;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.widget.TextView;
  8.  
  9. public class Main2Activity extends AppCompatActivity
  10. {
  11.  
  12.     TextView Name, Password;
  13.     SharedPreferences sharedPreference;
  14.  
  15.     @Override
  16.     protected void onCreate(Bundle savedInstanceState)
  17.     {
  18.         super.onCreate(savedInstanceState);
  19.         setContentView(R.layout.activity_main2);
  20.  
  21.         /*Bundle bundle = getIntent().getExtras();
  22.         String name = bundle.getString("Name");
  23.         String password = String.valueOf(bundle.getInt("Password"));
  24.         Name = findViewById(R.id.textView2);
  25.         Password = findViewById(R.id.textView3);
  26.  
  27.         sharedPreference = getSharedPreferences("file", 0);
  28.         String username = sharedPreference.getString("name", "No user found.");
  29.         int pass = sharedPreference.getInt("password", 0000);
  30.  
  31.         Name.setText("Welcome ");
  32.         Name.append(name);
  33.         Password.setText("Password: ");
  34.         Password.append(password);*/
  35.         SharedPreferences prefs = getSharedPreferences("file", 0);
  36.         String restoredText = prefs.getString("text", null);
  37.         if (restoredText != null) {
  38.             String name = prefs.getString("name", "No name defined");//"No name defined" is the default value.
  39.             int idName = prefs.getInt("idName", 0); //0 is the default value.
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment