2017-01-18 47 views
0

因此,我遇到了infamous Can not perform this action after onSaveInstanceState問題,並且遇到了一個困難時間,找出如何解決問題。在ViewPager中記錄然後登錄 - 無法在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它登錄時按預期工作。DO我需要重置視圖尋呼機?

回答

0

我打算刪除這個問題,因爲發現了錯誤,但認爲我會發布我的解決方案,只是在別人遇到這個問題。

我的錯誤是我用一個Singleton類來保存視圖尋呼機適配器

(我不記得究竟爲什麼我使用一個單獨的類,但它是這是導致錯誤。)

相關問題