Wait for user permission
Android continuing running the code and asking for GPS data ( = crash, because the user didn't accept the permission request).
Like many things in Android, requestPermissions()
is asynchronous. The user has not even been prompted for the permissions by the time this method returns.
How can I wait for user answer from the Android permission dialog ?
You don't.
If you find that you already have the permission, you do your work. If you find that you have to request permission, you delay doing that work until you get the permission, in onRequestPermissionsResult()
.
You can handle user response overriding method
public void onRequestPermissionsResult(
int requestCode,
String[] permissions,
int[] grantResults
)
from your activity.