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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:18:47+00:00 2026-06-10T23:18:47+00:00

I used a service to start a Thread, in this thread, I wrote a

  • 0

I used a service to start a Thread, in this thread, I wrote a while loop(I set a flag, while flag is true, the thread runs, if the flag is false, then the thread won’t do anything, thus stop the thread manually) in this thread. when I debug my code, I often noticed that the thread is over, but the service was still running. Is it recycled by android system?

How can I do to prevent my thread from recycling?

====== EDIT =======

“will by thread be cleaned up by the system automatically before it ends” – means the thread is being killed when it shouldn’t be

  • 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-10T23:18:49+00:00Added an answer on June 10, 2026 at 11:18 pm

    Are you calling Thread.yield() in your loop to allow the system to do other things? If not- then android could be killing the thread for consuming 100% CPU usage – if it’s a simple loop the stack-trace won’t change so it will thing your script hung

    http://developer.android.com/reference/java/lang/Thread.html#yield()

    Yield() tells the thread-executor that it should stop and run other threads before returning to yours, without it your loop will steal resources from other apps

    You can also sleep if you are sure your flag won’t change for a certain amount of time

    Edit – Background – it’s the way android detects hung threads – If a thread takes up 100% of the CPU then it dumps a stack trace to a file, waits a short amount of time and then dumps another stack trace – if the two match it assumes the code has stopped running and will either issue an ANR ‘xx is not responsing’ dialog for an activity, OR, if it’s a service, it will simply kill it and restart it automatically.

    By yielding you prevent it from consuming 100% so it never tries to do that.

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

Sidebar

Related Questions

I created a duplex service ( NetTcpBinding ) like this example : I used
I have the following function inside my WCF service. This function is used to
I have web service used by about a dozen C# projects and sites. The
i recently saw some videos on F#. it seems it used mainly for Service
I have used ksoap2 to call my SOAP service. It works fine in android2.2
I've used Visual Studio's Add Service Reference feature to add a service (actually it
We have a service account defined for anonymous access which is used for several
I am developing a web-service that will be used by several clients. I am
I have created a REST web service and successfully used it with a client.
I have written a Java service to run on a server. I used JMX

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.