我正在开发Android应用程序,它有两个不同的tabhost:Main和Child。 在主tabhost我有5个不同的标签,最后一个打开新的活动,我有登录页面。我想创建一个布尔类型isLoggedIn登录活动,并传递true或false到主选项卡栏,因为我想要更改如果用户登录,我会有5,如果没有,我会有4个选项卡。所以,如何编码此问题的任何建议?Android SharedPreference - TabHost问题
更新:
现在我用我用这个code.In用户LogIn.class:
SharedPreferences isLogged = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor = isLogged.edit();
editor.putBoolean("isLoggedIn", isLoggedIn);
editor.commit();
在MainActivity我使用几乎相同的代码:
SharedPreferences isLogged = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor = isLogged.edit();
editor.putBoolean("isLoggedIn", false);
editor.commit();
我检查两种状态:
if(editor.putBoolean("isLoggedIn", false) != null){
// show 5 tabs
}else
{
// show 4 tabs;
但是,当我打开我的应用程序,我得到5个选项卡,甚至在检查用户的状态之前。 任何想法如何解决这个问题? }