Marti Serra Molina
Marti Serra Molina

Reputation: 473

Do I have to call super.onRequestPermissionsResult(requestCode, permissions, grantResults) on RequestPermissionsResult?

I have this piece of code and I am not really sure if I should implement super.onRequestPermissionsResult(requestCode, permissions, grantResults) in the else block. I don't know why it should be needed.

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
        when (requestCode) {
            READ_EXTERNAL_STORAGE_REQUEST_CODE -> {
                if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    performAction()
                } else {
                    Toast.makeText(this, "You cancelled the permission", Toast.LENGTH_SHORT).show()
                }
            }

            else -> super.onRequestPermissionsResult(requestCode, permissions, grantResults)
        }
    }

I have seen that there is an implementation for this method in the Activity. What does super.onRequestPermissionsResult(requestCode, permissions, grantResults) do? Is it needed?

Upvotes: 1

Views: 1229

Answers (1)

snachmsm
snachmsm

Reputation: 19233

currently it isn't necessary, as this method is empty. its only uppon to you for handling perm request result

but still you should keep super call in else statement - in this case and all other similar (overriden empty methods). you never know when Android team/library author introduce some default behavior/callback handle in source code (of Android, AndroidX, custom lib etc.) lib without using @CallSuper annotation

Upvotes: 1

Related Questions