android记住密码和自动登陆
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText; public class DengLu extends Activity implements OnClickListener{
private EditText name;
private EditText password;
private CheckBox box1;
private CheckBox box2;
private SharedPreferences sharedPreferences;
private Button button; @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.denglu);
button = (Button) findViewById(R.id.button);
name = (EditText) findViewById(R.id.name);
password = (EditText) findViewById(R.id.password);
box1 = (CheckBox) findViewById(R.id.baocun);
box2 = (CheckBox) findViewById(R.id.zidong);
sharedPreferences = getSharedPreferences("zhuce", 0);
//记住密码
boolean isCheckBox1 =sharedPreferences.getBoolean("CheckBox1", false);
//自动登录
boolean isCheckBox2 =sharedPreferences.getBoolean("CheckBox2", false); String names=sharedPreferences.getString("name","");
String passwords=sharedPreferences.getString("password", ""); if(isCheckBox1){
if(!names.equals("")&&!passwords.equals("")){
name.setText(names);
password.setText(passwords);
box1.setChecked(true);
}else{
if(!names.equals("")){
name.setText(names);
}
} }
if(isCheckBox2){ Intent intent = new Intent(DengLu.this, ZhuYe.class);
startActivity(intent); }
button.setOnClickListener(this); } @Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.button:
if(box1.isChecked()){
sharedPreferences.edit().putBoolean("CheckBox1", true).commit();
sharedPreferences.edit().putString("name", name.getText().toString()).commit();
sharedPreferences.edit().putString("password", password.getText().toString()).commit(); }else{
sharedPreferences.edit().putBoolean("CheckBox1", false).commit();
sharedPreferences.edit().putString("name", name.getText().toString()).commit();
sharedPreferences.edit().putString("password", "").commit();
}
if(box2.isChecked()){
sharedPreferences.edit().putBoolean("CheckBox2", true).commit();
} Intent intent = new Intent(DengLu.this, ZhuYe.class);
startActivity(intent);
break; default:
break;
}
}
}
android记住密码和自动登陆的更多相关文章
- Android之记住密码与自动登陆实现
本文主要讲述了利用sharedpreference实现记住密码与自动登陆功能 根据checkbox的状态存储用户名与密码 将结果保存在自定义的application中,成为全局变量 布局文件 < ...
- Android 记住密码和自动登录界面的实现(SharedPreferences 的用法)
原文:http://blog.csdn.net/liuyiming_/article/details/7704923 SharedPreferences介绍: SharedPreferences是An ...
- php实现记住密码下次自动登陆
这篇博客里面还写到 实现“记住我的登录状态”的功能方法,简言之,就是对首先对session进行用户信息赋值,检测session,失效后,利用cookie对其赋值: 在实现过程中,根据网上一些代码贴,整 ...
- 一个简单WPF登陆界面,包含记住密码,自动登录等功能,简洁美观
简介:这是一个自己以前用WPF设计的登陆界面,属于一个实验性的界面窗体,如果用于产品还很有不足.但也是有一点学习价值.后台代码略有复杂,但基本上都有注释 分类,略有代码经验的一般都能看懂. 登陆界面外 ...
- Android记住密码自动登录的实现
我采用的是SharedPreferences来存取数据的,所以先简单的介绍一下SharedPreferences SharedPreferences是Android平台上一个轻量级的存储类,主要是保存 ...
- 基于localStorge开发登录模块的记住密码与自动登录
前沿||我是乐于分享,善于交流的鸟窝 先做写一篇关于登录模块中记住密码与自动登录的模块.鸟窝微信:jkxx123321 关于这个模块功能模块的由来,这是鸟大大的处女秀,为什么这么说呢?一天在群里,一个 ...
- php中实现记住密码下次自动登录的例子
这篇文章主要介绍了php中实现记住密码下次自动登录的例子,本文使用cookie实现记住密码和自动登录功能,需要的朋友可以参考下 做网站的时候经常会碰到要实现记住密码,下次自动登录,一周内免登陆,一个月 ...
- WinForm应用程序的开机自启、记住密码,自动登录的实现
一.思路: 1.开机自启,自然是需要用到注册表,我们需要把程序添加到电脑的注册表中去 2.记住密码,自动登录,开机自启,在页面的呈现我们都使用复选框按钮来呈现 3.数据持久化,不能是数据库,可以是sq ...
- Cookie实现记住密码、自动登录
前端代码 <form id="form" action="xxx" method="post"> <div> < ...
随机推荐
- mysql导入导出
1.导入整个库 进入数据库,source 进去的语句等同于直接连接数据库后数据的语句 >source /var/www/test.sql 或者 sy$ mysql -uroot -p 数据库名( ...
- imx6dl i2c4 support
imx6dl i2c4 support 最近的项目用到了imx6dl的i2c4,其实完全可以用gpio-i2c的方法来实现.既然imx6的datasheet中提到有4个i2c,那么一定可以生成i2c的 ...
- https://my.oschina.net/reesechou/blog/492265
https://my.oschina.net/reesechou/blog/492265
- UIFont 设置字体
abel.font = [UIFont fontWithName:@"Arial-BoldItalicMT" size:24]; 字体名如下: Font Family: Ameri ...
- memory leak at strcore.cpp
最近使用CString出现了内存泄露,后来发现是CString.GetBuffer之后没有ReleaseBuffer.
- lodash的运用
Object 对象 1._.merge(object, [sources]) 此方法类似于_.assign,除了它递归地将源对象的自有和继承的可枚举字符串键控属性合并到目标对象中. 如果存在目标值,将 ...
- 针对大的sql文件删除行操作
今天处理开发已导出的库的一个sql文件.未gzip压缩 ,1.3G 需要删除 17 18 24行的SET行. 想到了两个办法 1 sed 方法 主意 由于 sed 虽然指定行 进行 替换, 也会读完 ...
- shell中如何判断某一命令是否存在
参考: http://www.cnblogs.com/tuzkee/p/3755230.html https://segmentfault.com/q/1010000000156870 http:// ...
- 在HTML中调用iOS
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- jose4j / JWT Examples
jose4j / JWT Examples View History JSON Web Token (JWT) Code Examples Producing and consuming a sign ...