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 7657303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:59:46+00:00 2026-05-31T12:59:46+00:00

Is it possible to request location updates inside a service that is in a

  • 0

Is it possible to request location updates inside a service that is in a separate thread from the one that calls startService?

I have tried:

lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);

It keeps giving me the error:

java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

Can the background manager run inside a service that is in a separate thread, or does the location manager need to be called from an Activity?

  • 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-31T12:59:47+00:00Added an answer on May 31, 2026 at 12:59 pm

    You don’t necessarily have to receive the updates on the main thread, but you do have to have a valid Looper that the underlying service can use to pass callbacks through an internal Handler. Inherently, if you do everything on the main thread you’re good because this thread has an active Looper already attached.

    Have a look at the docs for Looper as they explain how to set up your background thread with a valid instance so it can be used for this purpose. There is also a version of requestLocationUpdates() that takes a Looper object. You could call requestLocationUpdates() while passing the result of Looper.getMainLooper() to allow the callbacks to be processed on the main thread even though you may not be able to attach the listener directly from that thread.

    Also, keep in mind that location updates are inherently asynchronous, and are not blocking your main thread just because you register the callbacks there. This may not be the reason you are interested in this, but I thought it worth mentioning.

    HTH

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

Sidebar

Related Questions

One possible solution could be simple HTTP get or post request, but that wouldn't
Is it possible to know that a HTTP request is from Ajax?If yes, how?
I have some problems with location systems. I have a service that implements locationlistener.
Possible Duplicate: JavaScript post request like a form submit I have a value calculated
Is it possible to get the raw HTTP Request from the HttpServletRequest object? I
Is it possible to place Facebook's request form inside a popup? Google is failing
I would like to get driving time information from one location to another using
Possible Duplicate: Android: how to cancel a request of Location update with intent? I
The app that I'm writing uses the GPS location manager service requestLocationUpdates() but I
I have an android application that gets user location every 2 minutes using requestLocationUpdates

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.