Skip to content

Instantly share code, notes, and snippets.

@gb103
Last active January 2, 2021 03:49
Show Gist options
  • Save gb103/24588d3f09d8684412afc0699da635ff to your computer and use it in GitHub Desktop.
Save gb103/24588d3f09d8684412afc0699da635ff to your computer and use it in GitHub Desktop.
Monitor the install progress
// Initializes a variable to later track the session ID for a given request.
var mySessionId = 0
// Creates a listener for request status updates.
val listener = SplitInstallStateUpdatedListener { state ->
if (state.sessionId() == mySessionId) {
// Read the status of the request to handle the state update.
}
}
// Registers the listener.
splitInstallManager.registerListener(listener)
...
splitInstallManager
.startInstall(request)
// When the platform accepts your request to download
// an on demand module, it binds it to the following session ID.
// You use this ID to track further status updates for the request.
.addOnSuccessListener { sessionId -> mySessionId = sessionId }
// You should also add the following listener to handle any errors
// processing the request.
.addOnFailureListener { exception ->
// Handle request errors.
}
// When your app no longer requires further updates, unregister the listener.
splitInstallManager.unregisterListener(listener)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment