Is onResume() called after onRequestPermissionsResult() in Android?
The correct chain of events is the following:
You call
requestPermissions
in the Activity's onCreaterequestPermissions
start running in another thread, because it is designed to not block the UI thread. So your activity goes through onStart and then onResumethe request of the permission generates a dialog, which fires onPause on the Activity, because it is no more in foreground position.
The activity at this moment is paused and you can see a dialog asking to allow or deny the permission.
You make your choice, the dialog gets resolved and onResume is called on the Activity.
Also notice that the onPause is fired by the dialog always after onStart and onResume of the Activity, no matter how long it takes to execute the code in them.
And now you can also see why you shouldn't put requestPermissions in onResume.
onResume()
will be called first during the launch of your Activity
as onRequestPermissionsResult(...)
will only be called after user accepts or denies permission to application in Permission request dialog. But onResume again gets called after onRequestPermissionsResult(...)
is called to allow your activity to take in account the user choice (granted or denied permission) and execute the code accordingly
The first one is onRequestPermissionsResult
!
I have destroy some object on onPause()
, and It will be recreate on onResume()
, but I find my onRequestPermissionsResult()
operate some destroyed object and caused NullPointEx