is there any way to leave a thread in background when i close the app in android? I read about a Service but implementing it is too much than i need. Thanks
Share
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.
That will happen by default. That does not mean it is a good idea.
More likely, it is precisely what you need.
If you start a thread in an
Activity, then fail to stop that thread, it will run forever, until Android terminates the process, since you have no way of stopping it. The only sort-of acceptable exception is if your thread stops itself, and then you have to be very very careful that it actually does terminate cleanly. On the other hand, you can arrange to stop a runningServicewhenever you need, from anyActivity, and thatServicecan arrange to stop the thread, so you don’t leak the thread indefinitely.I strongly encourage you to implement a service that manages the thread.