Solution: "locationManager. removeUpdates () cannot close gps positioning", locationmanager

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.