android – toggling location in settings makes my app no longer work

I am using this code on github, imported into Android Studio.

I have the permission ACCESS_FINE_LOCATION in the manifest file.

In Android Studio the emulator (Pixel XL api 25) has location turned ON by default.

Running the app for the first time on the emulator works and I get the latitude and longitude values.

However, with a big H, when I turn the location settings OFF and back ON again it no longer works, I have to kill the emulator and start from scratch.

I’m trying to get the location of a user for an app i’m building but i seems to be running into the problem of the user potentially wrecking my app by turning off location services for whatever reason.

Any help is greatly appreciated.