Solution: "locationManager. removeUpdates () cannot close gps positioning", locationmanager
Reprinted please indicate the source, thank you http://blog.csdn.net/harryweasley/article/details/41575731
I recently encountered a problem in the middle of a gps project. I called locationManager. after removeUpdates (listener), I thought gps Positioning would stop, but the gps positioning function was not stopped. The gps signal bar continued to flash, followed by various Baidu, I couldn't find the correct solution, and then I went over the wall to continue Google, and finally found a solution. Here I will record it to help those who are confused by this problem.
First, let's review the three steps for correctly disabling gps:
Step 1:
Remove LocationListener
Step 2:
Set LocationManager to null
Step 3:
Set LocationListener to null
The following is the code for correctly disabling gps. The name is determined by yourself.
if(_locationManager != null){ _locationManager.removeUpdates(<span style="font-family: Arial, Helvetica, sans-serif;">_locationListener</span>); _locationManager = null; } if(_locationListener != null) { _locationListener = null; }
If these steps do not work and your gps signal is still flashing, there are two potential problems to solve:
The first reason is:This is the most common and frustrating reason.You may have instantiated multiple locationmanagers intentionally or unintentionally.The simplest way to avoid this error is to put the instance LocationManager code in the onResume () event and disable it in the onPause () method. Carefully control the opened LocationManager and close it in time. When you LocationManager between different activities, you must pay attention to it. If the LocationManager is running and you instantiate another one, you will not be able to use the code to close it as expected, and you will have to manually close it.
The second reason is:It may be that another APP on your mobile phone has caused the LocationManager to run. Obviously, it will not be closed through your app. Multiple checks have eliminated this possibility, make sure that you have disabled all other apps that may use gps positioning.