android-smart-lock icon indicating copy to clipboard operation
android-smart-lock copied to clipboard

Crash When Implementing Multiple Saved Credentials

Open schordas opened this issue 9 years ago • 0 comments

When implement the multiple saved credentials there is a crash in the MainActivity. Here is the stack trace:

12369-12369/com.google.codelab.smartlock E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.google.codelab.smartlock, PID: 12369
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1493)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1511)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:638)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:617)
at com.google.codelab.smartlock.MainActivity.setFragment(MainActivity.java:190)
at com.google.codelab.smartlock.MainActivity.access$000(MainActivity.java:38)
at com.google.codelab.smartlock.MainActivity$1.run(MainActivity.java:81)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6872)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

It is caused by this block of code:

setFragment(null);
// When not using Smart Lock show set Fragment in onCreate.
mHandler = new Handler();
mHandler.postDelayed(new Runnable() {
    @Override
    public void run() {\
        setFragment(null);
    }
}, DELAY_MILLIS);

It seems like we are trying to call setFragment(null) when the fragment is onPause() or otherwise is not available for the state change.

I removed this block of code and I don't get the crash, but I'm not entirely sure the rest of the app will function properly.

schordas avatar May 20 '16 20:05 schordas