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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:20:16+00:00 2026-06-04T14:20:16+00:00

I am working on a service, which extends the Service class and using a

  • 0

I am working on a service, which extends the Service class and using a seperate thread to handle incoming messages, so, I have the following in my onCreate method

thread = new HandlerThread("MYSERVICE-THREAD",
        Process.THREAD_PRIORITY_BACKGROUND);

thread.start();
serviceLooper = thread.getLooper();
serviceHandler = new ServiceHandler(mServiceLooper);

In this thread, I create a LocationManager and sets it up to listen for location changes. I’m slightly worried about the lifecycle of the thread though. This is why:

If I don’t remove the location listeners from the location manager in the onDestroy method of the service, and force a location update via telnet, everything works fine. I found this strange and tried explicitly ending the thread with thread.quit() in onDestroy method of the service. So, now when doing a location update from telnet, I get the warning I was kind of expecting in the first place. That a handler was calling a handler on a dead thread.

removing the location listeners from the location manager obviously solves this, BUT, this seems to hint to me that if I dont explicitly close the thread, the thread will continue to run after the service is destroyed. Is this correct? In the examples on developer.android.com they dont explicitly close their thread, so I thought the VM would take care of it in this case.

  • 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-06-04T14:20:18+00:00Added an answer on June 4, 2026 at 2:20 pm

    Oh yes. This is the case. The same goes for Activities too. Threads stay open until Android explicitly kills them to free up resources unless you close them yourself. In a technical sense, Activities and Services are never closed when popped from the stack. It just tells the OS that all the resources that they were using can now be reclaimed when it’s needed so that memory pool will be the first place the OS looks. If a thread of any kind is still running however, it will continue to run (and take up CPU resources) until the memory is reclaimed which could be anywhere between 1 second and eternity.

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

Sidebar

Related Questions

I am working on one real estate website which is Using RETS service to
I have a .NET Windows Service which spawns a thread that basically just acts
I have a class reflecting my dbml file which extends DataContext, but for some
I have a already working Twig extension in my Symfony2 app: namespace Company\MyBundle\Service; class
I am working on a web service which is going to have both a
I have a remoting service which uses the Windows Auth. Been working fine for
I call a service which returns GMT dates. Its been working fine since November,
I'm working on a self-hosted WCF service for which encrypted communications is an option.
I am VERY new to PHP, I'm currently working on a service, part which
I am working on an application which starts as a service but only if

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.