Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onActivityResult() deprecated for AppCompatActivity

I am using in-app updates for android and as per the documentation, they are using onActivityResult to handle app behaviour incase the update is interrupted.

This is my function that is called from my fragment:

private fun startImmediateUpdate(appUpdateInfo: AppUpdateInfo) {
    appUpdateManager.startUpdateFlowForResult(
        appUpdateInfo,
        AppUpdateType.IMMEDIATE,
        requireActivity(),
        Constants.CODES.APP_UPDATE_REQUEST_CODE
    )

}

This is how i am handling results in parent activity

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    when (requestCode) {
        Constants.CODES.APP_UPDATE_REQUEST_CODE -> {
            if (resultCode != RESULT_OK || resultCode == RESULT_CANCELED || resultCode == ActivityResult.RESULT_IN_APP_UPDATE_FAILED) {
                //Do whatever i want to
            }
        }
    }
    super.onActivityResult(requestCode, resultCode, data)
}

Now super.onActivityResult(requestCode, resultCode, data) is deprecated. Things are working fine for now but i am worried the app will crash if its wiped out completely

What can i do to replace onActivityResult()? I have looked into registerForActivityResult() but could not find anything that suits my usecase.

like image 795
Hashir Ali Avatar asked Dec 22 '20 13:12

Hashir Ali


1 Answers

I have the same issue and I see that one possibility is to rewrite to use the startUpdateFlow call instead.

Personally, I think this is not worth doing, so I will ignore this specific deprecation warning instead and wait/hope for Android/Google to make a method where we can pass an ActivityResultLauncher instead.

like image 68
Anders Ullnæss Avatar answered Oct 11 '22 19:10

Anders Ullnæss