I am developing an app where I start a service if a particular feature (in my app) is enabled by user. I want to keep running this service even after user quits my app. How can I do this? plz help
1: You have to invoke the service's startForeground() method within 5 seconds after starting the service. To do this, you can call startForeground() in onCreate() method of service. public class AppService extends Service { .... @Override public void onCreate() { startForeground(9999, Notification()) } .... }
In android, by pressing a back button or home button. So put an event key listener for back & home button and terminate the service.
Right from developer.android.com
A service is a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface. For example, a service might play music in the background while the user is in a different application, or it might fetch data over the network without blocking user interaction with an activity. Another component, such as an activity, can start the service and let it run or bind to it in order to interact with it. A service is implemented as a subclass of Service and you can learn more about it in the Services developer guide.
So, as long as you create a service, and the user exits your app it will still run. Just like the example above.
This should give you all the information you need: https://developer.android.com/guide/components/services.html
you can use Alarm manager for any background service.
For particular timing you want to perform something which can be service.
And for the continues process,You can start service from alarm manager.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With