打开的时候,帐号和密码都有了(已经记住之前输入的),登录之后,按下返回键,但是密码和账户都不见了,只有退出应用后重新打开才会有是什么原因呢?真是百思不得其解
pref= PreferenceManager.getDefaultSharedPreferences(this);//静态方法
//pref=getPreferences(0);
zhanghaoshuru=(EditText)findViewById(R.id.zhanghaoshuru);
mimashuru =(EditText)findViewById(R.id.mimashuru);
denglu=(Button)findViewById(R.id.denglu) ;
jizhumima =(CheckBox)findViewById(R.id.jizhumima);boolean is=pref.getBoolean("data",false);
if( is){
String a=pref.getString("zhanghaoshuru","");
String b =pref.getString("mimashuru","");
zhanghaoshuru.setText(a);
mimashuru.setText(b);
jizhumima.setChecked(true);
} else{}
denglu.setOnClickListener(new View.OnClickListener() {
@SuppressLint("ShowToast")
@Override
public void onClick(View view) {
String a=zhanghaoshuru.getText().toString();
String b=mimashuru.getText().toString();
if(a.trim().equals("admin")&&b.trim().equals("admin")){
editor=pref.edit();
if(jizhumima.isChecked()){
editor.putBoolean("data",true) ;
editor.putString( "zhanghaoshuru" , a );
editor.putString( "mimashuru" , b );
}
else {
editor.putBoolean("data",false) ;
editor.clear(); }editor.apply();
Intent intent=new Intent(denglumima.this,MainActivity.class);
startActivity(intent);
pref= PreferenceManager.getDefaultSharedPreferences(this);//静态方法
//pref=getPreferences(0);
zhanghaoshuru=(EditText)findViewById(R.id.zhanghaoshuru);
mimashuru =(EditText)findViewById(R.id.mimashuru);
denglu=(Button)findViewById(R.id.denglu) ;
jizhumima =(CheckBox)findViewById(R.id.jizhumima);boolean is=pref.getBoolean("data",false);
if( is){
String a=pref.getString("zhanghaoshuru","");
String b =pref.getString("mimashuru","");
zhanghaoshuru.setText(a);
mimashuru.setText(b);
jizhumima.setChecked(true);
} else{}
denglu.setOnClickListener(new View.OnClickListener() {
@SuppressLint("ShowToast")
@Override
public void onClick(View view) {
String a=zhanghaoshuru.getText().toString();
String b=mimashuru.getText().toString();
if(a.trim().equals("admin")&&b.trim().equals("admin")){
editor=pref.edit();
if(jizhumima.isChecked()){
editor.putBoolean("data",true) ;
editor.putString( "zhanghaoshuru" , a );
editor.putString( "mimashuru" , b );
}
else {
editor.putBoolean("data",false) ;
editor.clear(); }editor.apply();
Intent intent=new Intent(denglumima.this,MainActivity.class);
startActivity(intent);
解决方案 »
- android屏幕上绘图问题,亟待高手解决!!
- 导入一个Android 项目后,注释中文乱码,怎么办?
- 无法访问网络的问题
- 苦寻Android SDK最新完整版
- android app 与 flash通信的问题。
- android studio 上手使用 大水逼问题
- 请问下像内置mail应用那样的ListView带CheckBox的效果怎么做?
- 使用adb shell使用sqlite3出错
- 关于如何访问已root设备的/data目录
- Installation error:INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION
- android人脸识别如何识别人的年龄?大牛们能否给点思路啊????
- Android studio前几天还能运行,后来在C盘里移除了个东西,然后再打开就如下图所示了
EditText zhanghaoshuru,mimashuru;
Button denglu;
CheckBox jizhumima;
SharedPreferences pref;
SharedPreferences.Editor editor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pref= PreferenceManager.getDefaultSharedPreferences(this);//静态方法
//pref=getPreferences(0);
zhanghaoshuru=(EditText)findViewById(R.id.zhanghaoshuru);
mimashuru =(EditText)findViewById(R.id.mimashuru);
denglu=(Button)findViewById(R.id.denglu) ;
jizhumima =(CheckBox)findViewById(R.id.jizhumima); boolean is=pref.getBoolean("data",false);
if( is){
String a=pref.getString("zhanghaoshuru","");
String b =pref.getString("mimashuru","");
zhanghaoshuru.setText(a);
mimashuru.setText(b);
jizhumima.setChecked(true);
}
else{
denglu.setOnClickListener(new View.OnClickListener() {
@SuppressLint("ShowToast")
@Override
public void onClick(View view) {
String a=zhanghaoshuru.getText().toString();
String b=mimashuru.getText().toString();
if(a.trim().equals("admin")&&b.trim().equals("admin")){
editor=pref.edit();
if(jizhumima.isChecked()){
editor.putBoolean("data",true) ;
editor.putString( "zhanghaoshuru" , a );
editor.putString( "mimashuru" , b );
}
else {
editor.putBoolean("data",false) ;
editor.clear(); }editor.apply();
Intent intent=new Intent(MainActivity.this,denglumima.class);
startActivity(intent);
}
}
});
}
}
}
可这时想要按登录按钮却一点反应都没有,没跳转