Get the App
SLTechnology News&Howtos  ›  Development  › 

How to set up the function of remembering login account password in Android development

Shulou Source: shulou.com Published: 2022-06-01 12:07:59 10月03日 Update

This article mainly introduces how to set up the function of remembering login account password in Android development, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.

First, page building

Second, code implementation

Package com.hiscene.test;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.text.TextUtils;import android.view.View;import android.widget.CheckBox;import android.widget.EditText;import android.widget.Toast;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.FileReader;import java.io.OutputStream;import java.io.OutputStreamWriter;public class MainActivity extends AppCompatActivity {EditText et_userName EditText et_password; CheckBox checkBox; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.login_layout); et_userName = findViewById (R.id.et_UserName); et_password = findViewById (R.id.et_Password); checkBox = findViewById (R.id.checkBox); LoadInfo ();} private void LoadInfo () {File file=new File ("data/data/com.hiscene.test/usre.txt") If (! file.exists ()) return; try {FileReader reader = new FileReader (file); BufferedReader br=new BufferedReader (reader); String text=br.readLine (); String [] arr=text.split ("#"); et_userName.setText (arr [0]); et_password.setText (arr [1]); checkBox.setChecked (true); br.close ();} catch (Exception e) {e.printStackTrace () }} public void Login (View view) {String userName=et_userName.getText () .toString () .trim (); String password= et_password.getText () .toString () .trim (); if (TextUtils.isEmpty (userName) | | TextUtils.isEmpty (password)) {Toast.makeText (MainActivity.this, "username or password cannot be empty!" , Toast.LENGTH_SHORT) .show (); return;} if (checkBox.isChecked ()) {File file=new File ("data/data/com.hiscene.test/usre.txt"); try {OutputStream out=new FileOutputStream (file); OutputStreamWriter osw=new OutputStreamWriter (out, "UTF-8"); BufferedWriter writer=new BufferedWriter (osw); writer.write (userName+ "#" + password); writer.flush () Writer.close ();} catch (Exception e) {e.printStackTrace ();} Thank you for reading this article carefully. I hope the article "how to set up the function of remembering login account password in Android development" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles passwords functions accounts development login code value interests at the same time more friends users user names knowledge editing industry information information channels pages Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Apple Shulou Technology MariaDB MySQL