因此,在 onSaveInstanceState 问题之后,我遇到了臭名昭著的无法执行此操作,并且很难弄清楚如何解决它。
onNavigationItemSelected
目前我可以通过菜单注销我的应用程序来导致它。
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
FirebaseAuth.getInstance().signOut();
goToLogin();
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
private void goToLogin() {
Intent x = new Intent(MainActivity.this, LoginActivity.class);
startActivity(x);
finish();
}
虽然当我重新登录应用程序时
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivityForResult(intent, REQUEST_SIGNUP);
finish();
然后尝试单击一个回收站视图项
CompletedViewPagerFragment completedViewPagerFragment = new CompletedViewPagerFragment();
Bundle bundle = new Bundle();
bundle.putInt(CompletedViewPagerFragment.KEY_COMPLETED_SELECTED, index);
completedViewPagerFragment.setArguments(bundle);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.placeholder, completedViewPagerFragment, VIEWPAGER_FRAGMENT);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
我收到 onSaveInstanceState 错误
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1832)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1850)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:643)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:603)
at com.example.jack.mhealth.MainActivity.onRecordingSelected(MainActivity.java:295)
我尝试使用 .commitAllowingStateLoss() 虽然这给了我一个活动已被破坏的错误
java.lang.IllegalStateException: Activity has been destroyed
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1854)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:643)
at android.support.v4.app.BackStackRecord.commitAllowingStateLoss(BackStackRecord.java:608)
at com.example.jack.mhealth.MainActivity.onRecordingSelected(MainActivity.java:294)
我真的不知道在注销和完成 MainActivity 到然后重新登录并导致 ViewPager 中断之间出了什么问题。
当应用程序新鲜时,它会直接进入登录屏幕,然后从 MainActivity:75 登录它在登录时按预期工作。我是否需要以某种方式重置视图寻呼机?