// 获取实例对象
        sp = this.getSharedPreferences("userInfo", Context.MODE_WORLD_READABLE);
        rem_pw = (CheckBox) findViewById(R.id.cb_mima);
        auto_login = (CheckBox) findViewById(R.id.cb_auto);

// 判断记住密码多选框的状态
        if (sp.getBoolean("ISCHECK", false)) {
            // 设置默认是记录密码状态
            rem_pw.setChecked(true);
            username.setText(sp.getString("USER_NAME", ""));
            Log.v("testtest", sp.getString("USER_NAME", ""));
            password.setText(sp.getString("PASSWORD", ""));
            Log.v("testtest", sp.getString("PASSWORD", ""));
            // 判断自动登陆多选框状态
            if (sp.getBoolean("AUTO_ISCHECK", false)) {
                // 设置默认是自动登录状态
                auto_login.setChecked(true);
                // 跳转界面
                Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                LoginActivity.this.startActivity(intent);

            }
        }



// 登录成功和记住密码框为选中状态才保存用户信息
                        if (rem_pw.isChecked()) {
                            // 记住用户名、密码、
                            Editor editor = sp.edit();
                            editor.putString("USER_NAME", user);
                            editor.putString("PASSWORD", pwd);
                            editor.commit();
                        }


// 监听记住密码多选框按钮事件
        rem_pw.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (rem_pw.isChecked()) {

                    System.out.println("记住密码已选中");
                    Log.v("testtest", "记住密码已选中");
                    sp.edit().putBoolean("ISCHECK", true).commit();

                }
                else {

                    System.out.println("记住密码没有选中");
                    Log.v("testtest", "记住密码没有选中");
                    sp.edit().putBoolean("ISCHECK", false).commit();

                }

            }
        });
        // 监听自动登录多选框事件
        auto_login.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (auto_login.isChecked()) {
                    System.out.println("自动登录已选中");
                    Log.v("testtest", "自动登录已选中");
                    sp.edit().putBoolean("AUTO_ISCHECK", true).commit();

                }
                else {
                    System.out.println("自动登录没有选中");
                    Log.v("testtest", "自动登录没有选中");
                    sp.edit().putBoolean("AUTO_ISCHECK", false).commit();
                }
            }
        });

    }

SharedPreferences

getBoolean(String key, boolean defValue):获取Boolean型数据

参数说明:boolean defValue 没有设置这个值,配置文件中没有  默认的返回值