I’m creating a service Thread for my application, this thread will perform background tasks, and therefore it’ll be usage only if my Main thread is running.
So should I declare it as a Daemon ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
On Android, it’s better to make sure you manage your threads explicitly. Tell them when to terminate.
See a related discussion here. They didn’t find a solution, and observed long-living threads instead:
What hooks do we have in order to do worker thread termination on application exit
Note that standard Java shutdown hooks are not guaranteed on this platform:
http://developer.android.com/reference/java/lang/Runtime.html#addShutdownHook%28java.lang.Thread%29
So, instead of relying on an (undocumented?) belief that Android will properly kill your VM anyway and guessing on daemon/not daemon, it seems to be better to control the threads.