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> < ...
随机推荐
- JavaScript学习之DIV层与图像
DIV层与图像 一.设计一个可定位的层 1.设置位置(position)和大小 (1)绝对定位(absolute):以页面边框为参照,只要设置好绝对位置,那么元素的位置会始终固定在距离边框某个位置的距 ...
- 开发报表时将已有User做成下拉列表,第一项为label为ALL,value为null
SELECT 'All' AS LABLE_NAME, NULL AS USER_NAMEUNION ALLSELECT USER_NAME AS LABLE_NAME, USER_NAME from ...
- 将option添加到select框
var select=document.createElement("select"); select.setAttribute("class","f ...
- 几个系统调用分析 glibc中的malloc调用和共享内存原理
本文主要分析内存以及I/O相关的系统调用和库函数的实现原理,根据原理给出在使用过程中需要注意的问题和优化的侧重点,本文涉及到的系统调用包括readahead,pread/pwrite,read/wri ...
- 网站购物,使用pickle
主程序, #!/usr/bin/env python #_*_ coding:utf- _*_ import pickle import os import sys import time impor ...
- iOS 瀑布流的Demo
/** * 瀑布流Demo的主要代码,若想看完整的代码请到下面链接去下载 * * 链接: https://pan.baidu.com/s/1slByAHB 密码: r3q6 */ #import &l ...
- 12C清理asm磁盘组和文件
磁盘清理(disk scrub)可以检查逻辑坏块,并使用镜像数据自动修复数据(必须是normal.high冗余级别).磁盘清理过程和磁盘组的rebalance相结合,可以减少对I/O资源的使用.清理过 ...
- ios app下载跳到itunes
<body class="box"> <div class="text"> <a href="https://itune ...
- linux:lnmp环境搭建
一.准备工作(把安装环境需要使用到的包都下载好) mysql(官网):http://dev.mysql.com/downloads/ php(官网):http://php.net/downloads. ...
- MVC 学习系列-Controller
MVC最核心的也就是Controller了,控制器(controller)在功能中起到了核心功能. 1,)在MVC类库中,根据URL,通过MVCHandler进入MVC处理系统中, 2,)解析初始化对 ...