Skip to content

Instantly share code, notes, and snippets.

@sakshampruthi
Last active June 28, 2022 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sakshampruthi/42e05a9fc694cc600146e02e5897c8d4 to your computer and use it in GitHub Desktop.
Save sakshampruthi/42e05a9fc694cc600146e02e5897c8d4 to your computer and use it in GitHub Desktop.
override fun onCreate(savedInstanceState: Bundle?) {
..
forceUpdate = remoteConfig().getBoolean(FORCE_UPDATE)
remoteConfig().fetchAndActivate().addOnSuccessListener {
checkInAppUpdate()
}
..
}
private fun checkInAppUpdate(){
..
appUpdateManager.startUpdateFlowForResult(
appUpdateInfo,
if(forceUpdate) AppUpdateType.IMMEDIATE else AppUpdateType.FLEXIBLE,
this,
IN_APP_UPDATE_REQUEST_CODE
)
..
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
IN_APP_UPDATE_REQUEST_CODE -> {
when(resultCode){
//close the app if user closes immediate update
Activity.RESULT_CANCELED -> {
if(forceUpdate) finishAffinity()
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment