this is a android app code ,is like this  main.class package com.example.myapplication; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.Toast; import android.widget.CompoundButton; public class MainActivity extends AppCompatActivity {     private SharedPreferences sharedpreferences;     private Editor editor;     private CheckBox check;     private boolean flag;     private EditText edit1;     private EditText edit2;     @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);         edit1 = (EditText) findViewById(R.id.editTextTextEmailAddress);         edit2 = (EditText) findViewById(R.id.editTextNumberPassword);         Button btnLogin = (Button) findViewById(R.id.btnLogin);         btnLogin.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {                 String userName = edit1.getText().toString();                 String userPassword = edit2.getText().toString();                 if (userName.equals(sharedpreferences.getString("account", &..n@123.com"))                         && userPassword.equals(sharedpreferences.getString("password", "1234"))) {                     openActivity2();                 } else {                     Toast.makeText(MainActivity.this, "Wrong username and password", Toast.LENGTH_SHORT).show();                 }             }         });         // Retrieve shared preferences and editor         sharedpreferences = getSharedPreferences("test", MODE_PRIVATE);         editor = sharedpreferences.edit();         // Retrieve the checkbox and set a listener         check = (CheckBox) findViewById(R.id.checkBox1);         check.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {             @Override             public void onCheckedChanged(CompoundButton arg0, boolean arg1) {                 // Save the checked state of the checkbox to shared preferences                 editor.putBoolean("rememberPassword", arg1);                 editor.commit();             }         });         // Retrieve the rememberPassword flag from shared preferences         flag = sharedpreferences.getBoolean("rememberPassword", false);         // If rememberPassword flag is set, autofill the email and password fields         if (flag) {             edit1.setText(sharedpreferences.getString("account", ""));             edit2.setText(sharedpreferences.getString("password", ""));             check.setChecked(true);         }     }     private void openActivity2() {         Intent intent=new Intent(this, PlayerActivity2.class);         startActivity(intent);     } ---- xml           ------ I hope to let it automatically log in next time after I check the remember password, enter the password. But I don't know why, after I checked Enter password after login, it didn't log in automatically. How to fix this problem.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

this is a android app code ,is like this 

main.class

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
import android.widget.CompoundButton;

public class MainActivity extends AppCompatActivity {
    private SharedPreferences sharedpreferences;
    private Editor editor;
    private CheckBox check;
    private boolean flag;

    private EditText edit1;
    private EditText edit2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        edit1 = (EditText) findViewById(R.id.editTextTextEmailAddress);
        edit2 = (EditText) findViewById(R.id.editTextNumberPassword);

        Button btnLogin = (Button) findViewById(R.id.btnLogin);
        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String userName = edit1.getText().toString();
                String userPassword = edit2.getText().toString();

                if (userName.equals(sharedpreferences.getString("account", &..n@123.com"))
                        && userPassword.equals(sharedpreferences.getString("password", "1234"))) {
                    openActivity2();
                } else {
                    Toast.makeText(MainActivity.this, "Wrong username and password", Toast.LENGTH_SHORT).show();
                }
            }
        });

        // Retrieve shared preferences and editor
        sharedpreferences = getSharedPreferences("test", MODE_PRIVATE);
        editor = sharedpreferences.edit();

        // Retrieve the checkbox and set a listener
        check = (CheckBox) findViewById(R.id.checkBox1);
        check.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // Save the checked state of the checkbox to shared preferences
                editor.putBoolean("rememberPassword", arg1);
                editor.commit();
            }
        });

        // Retrieve the rememberPassword flag from shared preferences
        flag = sharedpreferences.getBoolean("rememberPassword", false);

        // If rememberPassword flag is set, autofill the email and password fields
        if (flag) {
            edit1.setText(sharedpreferences.getString("account", ""));
            edit2.setText(sharedpreferences.getString("password", ""));
            check.setChecked(true);
        }
    }

    private void openActivity2() {
        Intent intent=new Intent(this, PlayerActivity2.class);
        startActivity(intent);
    }



----

xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".PlayerActivity2">

    <TextView
        android:id="@+id/textView9"
        android:layout_width="379dp"
        android:layout_height="49dp"
        android:layout_marginStart="28dp"
        android:text="Copyright  purposes."
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.863" />


    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="remember password"
        tools:layout_editor_absoluteX="152dp"
        tools:layout_editor_absoluteY="507dp" />


</androidx.constraintlayout.widget.ConstraintLayout>

 

------

I hope to let it automatically log in next time after I check the remember password, enter the password.
But I don't know why, after I checked Enter password after login, it didn't log in automatically. How to fix this problem.

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Linux
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education