11

一切正常'androidx.biometric:biometric:1.0.0-alpha03',但是当我使用最新版本构建我的项目'androidx.biometric:biometric:1.0.0-alpha04'并调用myBiometricPrompt.authenticate(promptInfo)它时会引发此异常:FragmentManager is already executing transactions.

这是堆栈跟踪:

 java.lang.IllegalStateException: FragmentManager is already executing transactions
        at androidx.fragment.app.FragmentManagerImpl.ensureExecReady(FragmentManager.java:2207)
        at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2267)
        at androidx.fragment.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:814)
        at androidx.biometric.BiometricPrompt.authenticateInternal(BiometricPrompt.java:525)
        at androidx.biometric.BiometricPrompt.authenticate(BiometricPrompt.java:465)
        at com.my.app.ui.LoginFragment.handleTouchIdAuth(LoginFragment.kt:161)
        at com.my.app.ui.LoginFragment.onViewCreated(LoginFragment.kt:62)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1471)
        at androidx.fragment.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2646)
        at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2416)
        at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2372)
        at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
        at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3273)
        at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229)
        at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:2466)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1483)
        at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
        at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269)
        at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229)
        at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:201)
        at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:620)
        at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1391)
        at android.app.Activity.performStart(Activity.java:7157)
        at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2937)
        at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
        at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

有谁知道发生了什么以及该怎么做?现在,我会坚持使用1.0.0-alpha03版本

谢谢!

4

3 回答 3

7

androidx.biometric:biometric:1.0.0-beta01通过提供第二个构造函数来解决问题。在此版本之前,我通过恢复来解决了这个问题,alpha03但现在有一个实际的解决方案可用。

您可以在此处beta01找到发行说明

我们为 BiometricPrompt 引入了第二个构造函数,它允许它托管在 Fragment 中(与现有的构造函数相反,它需要 FragmentActivity)。

您可以在此处BiometricPrompt找到新的构造函数文档

BiometricPrompt(Fragment fragment, Executor executor, BiometricPrompt.AuthenticationCallback callback)

要修复,请按照以下简单步骤操作:

  1. 更改您的 build.gradle 以使用生物识别版本1.0.0-beta01
  2. 使用新的构造函数。简而言之,将第一个参数更改为您的片段而不是活动。请参阅下面的代码更改:

    val biometricPrompt = BiometricPrompt(activity!!, executor, callback)
    // Change the above line to the below line
    val biometricPrompt = BiometricPrompt(this, executor, callback)
    
于 2019-09-04T15:57:19.583 回答
6

编辑:问题似乎已解决,请参阅@olearyj234 的评论/答案,了解解决 beta01 和更新版本问题的正确方法。

--

alpha04 似乎有问题,恢复到 alpha03 可以解决它。猜猜我们在升级之前必须等待 alpha05。

真希望 Google 等到生物识别库结束 alpha 之后再弃用指纹库……

于 2019-04-16T07:08:35.443 回答
0

最新版本问题依然存在androidx.biometric:biometric:1.0.0-beta01

修复它是从处理程序显示 biometricPrompt:

    val promptInfo = BiometricPrompt.PromptInfo.Builder()
            .setTitle(fragmentActivity.getString(title))
            .setNegativeButtonText(fragmentActivity.getString(negativeButtonText))
            .build()
    val biometricPrompt = BiometricPrompt(...)

    // display biometricPrompt from handler
    Handler().post {
        biometricPrompt.authenticate(promptInfo)
    }
于 2019-09-04T09:24:38.730 回答