For the past couple of days, I'm trying to implement the immediate in-app update functionality, which works fine, but it seems I'm being unable to handle the result code (e.g. user cancels the update) in fragment - onActivityResult() as the method isn't called at all.
After some fiddling I realized, that after refusing the update, the onActivityResult() is called, but for the parent activity, not the fragment where I need to handle the result, which makes sense.
I'm using the code from the default example, this is just an fragment excerpt, as the code is wrapped in Rx observer logic.
appUpdateManager.appUpdateInfo.addOnSuccessListener { appUpdateInfo ->
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.IMMEDIATE,
fragment.activity, UPDATER_REQUEST_CODE)
}
// Trying to handle the in-app update activity result in here with no luck
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == UPDATER_REQUEST_CODE) {
// Log onActivityResult() result code
}
}
Is there by any chance somebody, who stumbled upon the same problem?
Thanks guys a lot in advance.
I found the solution after diving deeper into the documentation, where it is stated, that method startUpdateFlowForResult() with different arguments should be used.
https://developer.android.com/reference/com/google/android/play/core/appupdate/AppUpdateManager
So the trick is to use this
instead of this