I have integrated the in-app updates feature by Google Play Core library using this link.
I am using immediate update option because we make various critical bug fixes regularly which are important to update.
Here are the cases when app doesn't crash and updates app successfully and when it crashes.
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)
I have also referred to this question and its answer, but cannot understand how this solution can be implemented.
I have searched a lot everywhere, but didn't find any feasible solution related to this problem.
If any of you out there have faced a similar issue, and your solution worked, do help me.
Since the InvocationTargetException is caused by another exception thrown by the invoked method, the underlying exception can be found using the getCause() method. Therefore, resolving the InvocationTargetException error equates to finding the actual exception and resolving it.
What Causes InvocationTargetException. The InvocationTargetException occurs mainly when working with the Java reflection API to invoke a method or constructor, which throws an exception.
The InvocationTargetException is a checked exception that holds an exception thrown by an invoked method or constructor. Since JDK 1.4, this exception has been retrofitted to conform to the general-purpose exception-chaining mechanism.
GenericEJBObject ; maybe it swallows the exception. Alternatively, start the app in debug mode and set a break point in all the constructors of InvocationTargetException . Note: This might turn out to be impractical because other code causes a ton of these exceptions long before you get to the place you want to debug.
From what I have understand, you are trying to use the same instance of the AppUpdateInfo
somewhere, where its Intent
is a rather PendingIntent
that you are trying to use multiple times. Since a PendingIntent
can be used only once, it throws the exception. To solve this I am guessing you have an option.
If you are able to reproduce this bug locally, call startUpdateFlowForResult()
in a try-catch method and try to catch IntentSender$SendIntentException
, or InvocationTargetException
. If the exception is catched, that means the PendingIntent
is used already. Assuming that your checkUpdates()
method can be used recursively, call checkUpdates()
again, which should create a new AppUpdateManager
instance and start the lifecycle again, which will result in a new, fresh AppUpdateInfo
as a result, hence the new PendingIntent
that should let you open the app update popup again.
Edit: I'm not sure but what happens when onResume
code executes again? Like, checkForUpdates
is called but you are also replacing the mAppUpdateManager
in onResume
call, by calling AppUpdateManager.getInstance(this)
. So, it is a possibility that the mAppUpdateManager.appUpdateInfo
might not belong to the newly assigned mAppUpdateManager
in onResume
, since on application startup both onCreate
and onResume
is called. Hence, the object itself may not belong to the AppUpdateManager
itself.
A solution might be using two different managers, however I think the mechanism itself will return a singleton which makes them both same (maybe?) anyway, you need to check the address endpoints while in debug mode. The debug object should look like AppUpdateManager@2b62aa
, check if the managers are different or not. If they become different as I predict, your problem should be resolved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With