Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6176987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:11:45+00:00 2026-05-24T00:11:45+00:00

I am following the Android Location Deep Dive tutorial . In a part of

  • 0

I am following the Android Location Deep Dive tutorial. In a part of the code, a receiver is registered like this.

IntentFilter locIntentFilter = new 
IntentFilter(SINGLE_LOCATION_UPDATE_ACTION);
context.registerReceiver(singleUpdateReceiver, locIntentFilter);

In another part of the code, we find the following;

singleUpatePI = PendingIntent.getBroadcast(context, 0, updateIntent, PendingIntent.FLAG_UPDATE_CURRENT);
locationManager.requestSingleUpdate(criteria, singleUpatePI);

The Idea is that the LocationManager wil fire the SingleUpdatePI Pending intent when a location of the given accuracy criteria is available. My receiver called “singleUpdateReceiver” will be invoked, since I registered it earlier

It works, but my SingleUpdateReceiver’s onReceive method is invoked twice(!). This causes problems because I take care to unregister it the first time. No extras are available in any of the invocations.

Can anyone explain why locationManager.requestSingleUpdate(..) will fire the pending intent twice? This causes some problems because the first thing I do in my receiver is to unregister it like this

context.unregisterReceiver(singleUpdateReceiver);

On the second invocaiton, the receiver is not registered and an exception is thrown.

Tested on Android 2.3.3 HTC Sensation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:11:46+00:00Added an answer on May 24, 2026 at 12:11 am

    I believe this is happening because of the following line…

    criteria.setAccuracy(Criteria.ACCURACY_LOW);
    

    It should be…

    criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    

    I haven’t noticed the onReceive(...) method getting called twice after this change. Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am following this tutorial https://developer.android.com/guide/tutorials/views/hello-tabwidget.html and have completed it. Now I would actually
When I take pictures using android.hardware.camera and I save them to the following location
I have the following code for Android which works fine to play a sound
I have the following code running on my Android device. It works great and
I would like to implement the following simple pattern in an android app: Activity
I have written following code to get location name package demo.gps.locname; import java.io.IOException; import
I am using the following to mock my location in Android. public class GPSwork
I have an image that is in the following location (it's in my android
I am following this article to learn how to open new screen on button
I am attempting to create a MapView application following the tutorial from the Android

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.