In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.