我登录后要存储登录名时创建了一个登录活动,然后打开了主活动,但是当我按“后退”按钮时,我进入了登录活动。
我想停止应用程序,并且当我在主要活动中按返回按钮时。
我再次打开我的应用程序,请参阅登录活动。
我想将登录详细信息存储在本地,当我打开应用程序时,请从本地检查凭据,然后打开“主要活动”而不是“登录活动”。
请帮我说明一下你做了什么?
我的密码
@Override
protected void onPostExecute(String result) {
String str = result.trim();
if(str.equals("success")) {
startActivity(new Intent(Login.this,MainActivity.class));
}
else{
Toast.makeText(Login.this, "Either Username or Password is not correct", Toast.LENGTH_SHORT).show();
}
dialog.dismiss();
}
当按下后退按钮在登录活动上使用finish()方法时,不再显示登录活动。
@Override
protected void onPostExecute(String result) {
String str = result.trim();
if(str.equals("success")) {
startActivity(new Intent(Login.this,MainActivity.class));
finish();
}
else{
Toast.makeText(Login.this, "Either Username or Password is not correct", Toast.LENGTH_SHORT).show();
}
dialog.dismiss();
}
并按下返回按钮杀死应用程序
@Override
public void onBackPressed() {
Login.this.finish;
}
并且最好使用sharedpreference来存储用户是否登录(而不是String)。
希望对您有所帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句