gpt4 book ai didi

android - java.lang.reflect.InvocationTargetException 在进行应用更新时

转载 作者:行者123 更新时间:2023-12-03 13:26:44 31 4
gpt4 key购买 nike

我使用 this 集成了 Google Play Core 库的应用内更新功能关联。

我正在使用立即更新选项,因为我们会定期进行各种重要的错误修复,这些修复对更新很重要。

以下是应用程序不会崩溃并成功更新应用程序以及崩溃的情况。

  • 当应用程序更新可用时单击“更新”按钮,让更新正常完成而不会在两者之间中断 - 应用程序更新成功。
  • 单击“更新”按钮,更新开始下载,但用户通过按“更新下载进度条”后出现的“x”按钮取消更新 - 应用更新已取消。
  • 尝试再次打开应用程序,它会因以下错误而崩溃。

  • Fatal Exception: java.lang.RuntimeException java.lang.reflect.InvocationTargetException com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:586) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:942) Caused by java.lang.reflect.InvocationTargetException java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:942) Caused by android.content.IntentSender$SendIntentException android.app.Activity.startIntentSenderForResultInner (Activity.java:5019) com.google.android.play.core.appupdate.b.startUpdateFlowForResult (Unknown Source:5) co.behtarinternal.app.menu.MenuActivity$checkForAppUpdate$1.onSuccess (MenuActivity.kt:239) co.behtarinternal.app.menu.MenuActivity$checkForAppUpdate$1.onSuccess (MenuActivity.kt:43) com.google.android.play.core.tasks.e.run (Unknown Source:27) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:942)



    我也提到了 this问题及其 answer ,但无法理解如何实现此解决方案。

    我到处搜索了很多,但没有找到与此问题相关的任何可行解决方案。

    如果你们中的任何人都遇到过类似的问题,并且您的解决方案有效,请帮助我。

    最佳答案

    据我了解,您正在尝试使用 AppUpdateInfo 的相同实例某处,它的Intent是一个相当PendingIntent您尝试多次使用。由于 PendingIntent只能使用一次,会抛出异常。为了解决这个问题,我猜你有一个选择。

    如果您能够在本地重现此错误,请调用 startUpdateFlowForResult()在 try-catch 方法中并 try catch IntentSender$SendIntentException , 或 InvocationTargetException .如果异常被捕获,这意味着 PendingIntent已经使用了。假设您的 checkUpdates()方法可以递归使用,调用checkUpdates()再次,这应该会创建一个新的 AppUpdateManager实例并再次启动生命周期,这将产生一个新的 AppUpdateInfo因此,新的 PendingIntent这应该让您再次打开应用程序更新弹出窗口。

    编辑:我不确定,但是当 onResume 时会发生什么?代码再次执行?喜欢,checkForUpdates被调用,但您也替换了 mAppUpdateManageronResume调用,调用 AppUpdateManager.getInstance(this) .因此,mAppUpdateManager.appUpdateInfo 有可能可能不属于新分配的mAppUpdateManageronResume , 因为在应用程序启动时,onCreateonResume叫做。因此,对象本身可能不属于 AppUpdateManager本身。

    一个解决方案可能是使用两个不同的管理器,但是我认为该机制本身将返回一个使它们都相同(也许?)的单例,无论如何,您需要在 Debug模式下检查地址端点。调试对象应类似于 AppUpdateManager@2b62aa , 检查管理者是否不同。如果它们像我预测的那样变得不同,那么您的问题应该得到解决。

    关于android - java.lang.reflect.InvocationTargetException 在进行应用更新时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59467272/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com