I have a services can be called by other activities and threads and some receivers wait for the callback from it. I know that a service is only one instance in my app.
I want to run the service when it needs to be called, not all the time hanging on in the background. How can I start/stop the service safely? Thanks in advance.
I have a services can be called by other activities and threads and some
Share
Use IntentService.
Its very much like your needs. It starts when you want it to be…and stop when it got done its tasks automatically. So frees its memory immediately. Another big advantage is that it runs in its own thread, hence your main thread/UI will never halt.
If you decide that this answers your question, please mark it as “accepted”. This will raise both your and my reputation score.