【发布时间】:2018-09-22 07:47:25
【问题描述】:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Login.this);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("UID", jobj1.getString("admin_id").toString());
editor.apply();
Toast toast = Toast.makeText(Login.this, "Login Successfully", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
Intent i1=new Intent(Login.this,DashBoard.class);
startActivity(i1);
finish();
这是我使用 Intent 的注销代码,我想在单击注销按钮时清除 SharedPreference。
case "Logout":
Intent i5=new Intent(context1, Login.class);
i5.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context1.startActivity(i5);
((DashBoard)context1).finish();
Toast.makeText(context1,"Logout",Toast.LENGTH_LONG).show();
【问题讨论】:
-
问之前有没有试过搜索?
-
是的,先生,但代码对我不起作用。
-
代码应该做什么?哪个代码不起作用?究竟有什么不同?
-
code not work for me显示您尝试了哪些代码。 -
logout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // 启动新闻源屏幕 SharedPreferences preferences =getSharedPreferences("loginPrefs",Context.MODE_PRIVATE); SharedPreferences .Editor editor = preferences.edit(); editor.clear(); editor.commit(); finish(); });
标签: java android sharedpreferences logout android-sharedpreferences