Start A Service In Oncreate Of Application
I am trying to start a service when my app begins, and I need it the service to restart, incase a user decides to force close the service, even though the app is running(its ok, fo
Solution 1:
Using bindService()
from an Application
is pointless, as you will never be able to call unbindService()
.
Best, of course, would be for your service to only be in memory if it is actively delivering value to the user, instead of just because some other component of your app happens to be loaded. As it stands, you are headed down a path towards leaking this service, if you go with your plan of using startService()
from the Application
. There is no real concept in Android of "the app is running" as a lifecycle construct, so you will not have a logical time to stop the service.
(BTW, while Application
has an onTerminate()
method, it will never be called)
Post a Comment for "Start A Service In Oncreate Of Application"