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记住密码和自动登陆的更多相关文章

  1. Android之记住密码与自动登陆实现

    本文主要讲述了利用sharedpreference实现记住密码与自动登陆功能 根据checkbox的状态存储用户名与密码 将结果保存在自定义的application中,成为全局变量 布局文件 < ...

  2. Android 记住密码和自动登录界面的实现(SharedPreferences 的用法)

    原文:http://blog.csdn.net/liuyiming_/article/details/7704923 SharedPreferences介绍: SharedPreferences是An ...

  3. php实现记住密码下次自动登陆

    这篇博客里面还写到 实现“记住我的登录状态”的功能方法,简言之,就是对首先对session进行用户信息赋值,检测session,失效后,利用cookie对其赋值: 在实现过程中,根据网上一些代码贴,整 ...

  4. 一个简单WPF登陆界面,包含记住密码,自动登录等功能,简洁美观

    简介:这是一个自己以前用WPF设计的登陆界面,属于一个实验性的界面窗体,如果用于产品还很有不足.但也是有一点学习价值.后台代码略有复杂,但基本上都有注释 分类,略有代码经验的一般都能看懂. 登陆界面外 ...

  5. Android记住密码自动登录的实现

    我采用的是SharedPreferences来存取数据的,所以先简单的介绍一下SharedPreferences SharedPreferences是Android平台上一个轻量级的存储类,主要是保存 ...

  6. 基于localStorge开发登录模块的记住密码与自动登录

    前沿||我是乐于分享,善于交流的鸟窝 先做写一篇关于登录模块中记住密码与自动登录的模块.鸟窝微信:jkxx123321 关于这个模块功能模块的由来,这是鸟大大的处女秀,为什么这么说呢?一天在群里,一个 ...

  7. php中实现记住密码下次自动登录的例子

    这篇文章主要介绍了php中实现记住密码下次自动登录的例子,本文使用cookie实现记住密码和自动登录功能,需要的朋友可以参考下 做网站的时候经常会碰到要实现记住密码,下次自动登录,一周内免登陆,一个月 ...

  8. WinForm应用程序的开机自启、记住密码,自动登录的实现

    一.思路: 1.开机自启,自然是需要用到注册表,我们需要把程序添加到电脑的注册表中去 2.记住密码,自动登录,开机自启,在页面的呈现我们都使用复选框按钮来呈现 3.数据持久化,不能是数据库,可以是sq ...

  9. Cookie实现记住密码、自动登录

    前端代码 <form id="form" action="xxx" method="post"> <div> < ...

随机推荐

  1. 如何解决.NET Framework4.0的System.EnterpriseServices could not found 的问题

    我今天建基于.NET Framework4.0的webSite时报错 “System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, Pub ...

  2. iOS开发中 在MRC中让某些类使用ARC编译 或者相反

    如果你的工程是MRC 想让某些类使用ARC进行编译的话 那么需要在Build Phases中Complile Sourse 把该类后面 写上如下命令:-fobjc-arc  反之 写上如下命令:-fn ...

  3. ul和ol的一些知识

    ul和ol的一些知识 div#div0 ul{ border:1px solid #ccc; list-style:none; } div#div0 ul li{ border:1px solid g ...

  4. http://blog.csdn.net/jiyiqinlovexx/article/details/38326865

    http://blog.csdn.net/jiyiqinlovexx/article/details/38326865

  5. JQuery:JQuery的尺寸

    JQuery:尺寸 介绍:通过 jQuery,很容易处理元素和浏览器窗口的尺寸.jQuery 提供多个处理尺寸的重要方法:width().height().innerHeight().outerWid ...

  6. Java遇见HTML——JSP篇之JSP指令与动作元素

    一.include指令(如:<%@include file="..."%> ) 示例: Date.jsp <%@page import="java.te ...

  7. Java HashMap Demo

    代码: import java.util.HashMap; import java.util.Iterator; import java.util.Set; import java.util.Map. ...

  8. Spring Boot flyway的启动时机比较早

    flyway,如果已经创建的版本V1中已经更新,则会validation报错 at org.springframework.boot.devtools.restart.RestartLauncher. ...

  9. How to use JDBC-Authentication of Spring Boot/Spring Security with Flyway

    java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.conte ...

  10. mysql在线改表结构 pt-online-schema-change

    https://www.percona.com/doc/percona-toolkit/2.1/pt-online-schema-change.html 不锁表更改数据库表结构 pt-online-s ...