0

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.

Mike
  • 1,313
  • 12
  • 21

1 Answers1

0

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

snachmsm
  • 17,866
  • 3
  • 32
  • 74
  • Well I know the respective behaviors, I'm just thinking if there are possible workarounds for this, since my Snackbars have actions. Exception also occurs on completeUpdate() call. – Mike Jul 13 '20 at 09:13
  • if you destroy layout/`View` (e.g. by leaving `Activity`) then you can't update it, there is no workaround for this, its gone... you may create some manager (maybe singleton or `Application` class usage), which handle complete update listener call and at the moment of interface call you have to search for proper container in current `Activity`. don't refer to any `View` strictly, as update is background process and foreground may change during work – snachmsm Jul 13 '20 at 09:35