Shared Preference for current user name

This commit is contained in:
2023-12-20 11:18:03 +02:00
parent 8f724451c1
commit fbca53d3fc
4 changed files with 15 additions and 18 deletions

View File

@@ -1,11 +1,11 @@
package com.example.myapp_1;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@@ -13,10 +13,10 @@ import androidx.appcompat.app.AppCompatActivity;
import com.example.myapp_1.DB.DBOperations;
public class LoginActivity extends AppCompatActivity {
SharedPreferences currentUserThings = getSharedPreferences("UserData", MODE_PRIVATE);
EditText username;
EditText password;
TextView forgetpassword;
Button login;
Button signup;
@@ -30,17 +30,12 @@ public class LoginActivity extends AppCompatActivity {
username = findViewById(R.id.editTextText);
password = findViewById(R.id.editTextTextPassword);
// forgetpassword = findViewById(R.id.forgetpass);
login = findViewById(R.id.button);
signup = findViewById(R.id.button2);
guestLogin= findViewById(R.id.button3);
// forgetpassword.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// Intent newScreen = new Intent(getApplicationContext(), PasswordResetActivity.class);
// startActivity(newScreen);
// }
// });
login = findViewById(R.id.loginButton);
signup = findViewById(R.id.signupButton);
guestLogin= findViewById(R.id.guestButton);
SharedPreferences.Editor editor = currentUserThings.edit();
signup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -54,6 +49,7 @@ public class LoginActivity extends AppCompatActivity {
@Override
public void onClick(View v) {
editor.putString("username", "Guest");
Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(newScreen);
}
@@ -72,6 +68,7 @@ public class LoginActivity extends AppCompatActivity {
// Login successful
// Proceed to the next screen or perform other actions
Toast.makeText(LoginActivity.this,"Welcome", Toast.LENGTH_LONG).show();
editor.putString("username", "Guest");
Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(newScreen);