WSDOT / wsdot-android-app

Source code for the WSDOT Android application
GNU General Public License v3.0
19 stars 12 forks source link

Crash when rotating device while asking for permissions. #118

Closed loganSims closed 7 years ago

loganSims commented 7 years ago

Looks like when the device is rotated enableMyLocation(); is called again after the config change, which makes another permissions request where int[] grantResults is an empty array causing the crash.

Adding a check for grantResults.length > 0 fixes the issue, but I would like a better fix. Something to let the Activity know it's already asking for permissions after a config change.

loganSims commented 7 years ago

Checking grantResults may be the best way to handle this actually.

From the Android Reference pages:

Note: It is possible that the permissions request interaction with the user is interrupted. In this case you will receive empty permissions and results arrays which should be treated as a cancellation.

https://developer.android.com/reference/android/support/v4/app/ActivityCompat.OnRequestPermissionsResultCallback.html

Seems when we rotate the screen and the second permissions request is called one of them is canceled (I assume the first) and onRequestPermissionsResult gets called with the empty arrays causing the crash.