Calling appUpdateManager.completeUpdate() can crash my app if I move to a different fragment / activity

254 Views Asked by At

I've been recently trying out Android's in-app-update API here https://developer.android.com/guide/playcore/in-app-updates and calling appUpdateManager.completeUpdate() this method after successfully downloading the update seems to work, if I stay put on the view (fragment / activity) or rest my app in the background, but if I move to my app's other view it crashes, This is similar to Snackbar implementation trying to find views when the update fails or is cancelled but I move to a different fragment / activity. Is there a more efficient way to handle this globally throughout the app? It's really hard to debug it since you need an internal production build to test it out.

A similar solution I can think of is how toast behaves, even if you kill the view / activity, the toast will still show to the user, but I still want to use Snackbar and also need to call completeUpdate() if download is finished, where my user still has the freedom to browse the app and not crash.

1

There are 1 best solutions below

2
On

Snackbar needs CoordinatorLayout to be shown (most common usage), it's just a View, so when you want to show it, you need active GUI on foreground. when you start app update and move somewhere where Snackbar can't be shown then your Exception occurs

Toast is kind of system service with possibility to be shown on top of everything, completely different approach. for showing Toast you need only Context