我有一个应用程序android在哪里开始第一步bundle.putString ("statusLogin", "unlogged");
引用我的登录状态,所以一些功能隐藏按钮。
在我的菜单项中,选项“以管理员身份登录”,在执行登录后,为该捆绑包执行新参数:bundle.putString ("statusLogin", "Logged")
,因此我设置了仅允许管理员使用的按钮。
直到那时很好,但在菜单项中拥有按钮“Init”,我需要在不创建新按钮的情况下查找Bundle的状态,以便我可以验证它是否已登录并显示允许的按钮。< / p>
这是我的主要活动
public class PrincipalActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_principal);
FragmentManager fragmentManager = getSupportFragmentManager();
Bundle bundle = new Bundle();
bundle.putString("statusLogin", "Unlogged");
TelaInicialFragment fragobj = new TelaInicialFragment();
fragobj.setArguments(bundle);
fragmentManager.beginTransaction().replace(R.id.principal, fragobj).commit();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_principal, menu);
return super.onCreateOptionsMenu(menu);
}
public static PrincipalActivity newInstance(Context context) {
PrincipalActivity principalActivity = new PrincipalActivity();
return principalActivity;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
FragmentManager fragmentManager = getSupportFragmentManager();
int itemId = item.getItemId();
switch (itemId) {
case R.id.init:
Bundle bundle = new Bundle();
bundle.putString("statusLogin", "Unlogged");
TelaInicialFragment fragobj = new TelaInicialFragment();
fragobj.setArguments(bundle);
fragmentManager.beginTransaction().replace(R.id.principal, fragobj).commit();
break;
case R.id.sincronizar:
break;
case R.id.logarAdmin:
fragmentManager.beginTransaction().replace(R.id.principal, new LoginFragment()).commit();
break;
case R.id.sair:
finish();
break;
default:
return false;
}
return true;
}
}
如何检查Bundle
状态以确保用户当前已通过身份验证?