在Smart Lock示例应用程序中使用库com.android.support:design:23.1.1+时出错

时间:2016-03-31 07:08:18

标签: android google-smartlockpasswords

我从Google下载了应用程序Smart Lock for passwords的示例。 除了使用库< = 23.0.1?

之外是否有其他解决方案

库中的错误?

使用库com.android.support:design:23.1.1 +:

时发生错误
03-31 09:53:18.828 16779-16779/com.google.codelab.smartlock E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.google.codelab.smartlock, PID: 16779
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:634)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:613)
at com.google.codelab.smartlock.MainActivity.setFragment (MainActivity.java:119)
at com.google.codelab.smartlock.MainActivity.access$000(MainActivity.java:37)
at com.google.codelab.smartlock.MainActivity$1.run(MainActivity.java:79)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5253)
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:900)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695)

FATAL EXCEPTION

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:design:23.2.1'
compile 'com.google.android.gms:play-services-auth:8.4.0'
testCompile 'junit:junit:4.12'
}

2 个答案:

答案 0 :(得分:1)

  

Android compileSdkVersion是用于编译器的版本   构建应用程序.Android Support Library包是一组代码库,提供Android框架API的向后兼容版本以及仅通过库API提供的功能。

对于compileSdkVersion 23您可以使用风箱

调用+不是好方法

compile 'com.android.support:design:23.0.0'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:design:23.1.0'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:design:23.2.1'

答案 1 :(得分:0)

在Google的这个示例中,我更改了MainActivity中的以下代码:java:

    private void setFragment(Intent intent) {
    ...
    if (currentTag == null || !currentTag.equals(tag)) {
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.fragment_container, fragment, tag)
                .commit();
    }
}

要:

    private void setFragment(Intent intent) {
    ...
    if (currentTag == null || !currentTag.equals(tag)) {
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.fragment_container, fragment, tag)
                .commitAllowingStateLoss();
    }
}