I am asking for permission inside onActivityResult
of my activity and what is happening is that my activity is being paused while request permission dialog is disp
Source code of method Activity#requestPermissions:
public final void requestPermissions(@NonNull String[] permissions, int requestCode) {
if (requestCode < 0) {
throw new IllegalArgumentException("requestCode should be >= 0");
}
if (mHasCurrentPermissionsRequest) {
Log.w(TAG, "Can reqeust only one set of permissions at a time");
// Dispatch the callback with empty arrays which means a cancellation.
onRequestPermissionsResult(requestCode, new String[0], new int[0]);
return;
}
Intent intent = getPackageManager().buildRequestPermissionsIntent(permissions);
startActivityForResult(REQUEST_PERMISSIONS_WHO_PREFIX, intent, requestCode, null);
mHasCurrentPermissionsRequest = true;
}
We can clearly see that a new activity is opened. Hence onPause
in the calling activity will be surely called. So this is the expected behavior.
If you want to prevent pausing your activity, make sure you already have the required permissions before opening that activity.
If your activity is main activity, add an splash activity. Otherwise check for permissions before opening your activity.