Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger background service at a specific time in Android

I want to start a service in background everyday at a particular time. I am on android 2.2. please suggest me a sample code.

thanks

like image 826
sankara rao bhatta Avatar asked Jun 08 '11 04:06

sankara rao bhatta


People also ask

How do I trigger a service in Android?

You can start a service from an activity or other application component by passing an Intent to startService() or startForegroundService() . The Android system calls the service's onStartCommand() method and passes it the Intent , which specifies which service to start.

What is difference between background service and foreground service?

A Background Service is a service that runs only when the app is running so it'll get terminated when the app is terminated. A Foreground Service is a service that stays alive even when the app is terminated. And a Bound Service is a service that runs only if the component it is bound to is still active.

Does service run on main thread Android?

Service runs in the main thread of its hosting process; the service does not create its own thread and does not run in a separate process unless you specify otherwise.


1 Answers

You want the Android Alarm Manager:

This class provides access to the system alarm services. These allow you to schedule your application to be run at some point in the future.

And here is a tutorial for your viewing pleasure.

like image 195
Robert Massaioli Avatar answered Sep 21 '22 06:09

Robert Massaioli