[ACCEPTED]-Android regular task (cronjob equivalent)-cron
For Cron like tasks you have to use AlarmManager, this 3 is a system service, for using it in your 2 code you need to call:
AlarmManager myAlarmManager = Context.getSystemService(Context.ALARM_SERVICE).
Full docs about AlarmManager 1 here.
The most suitable approach is through services. I 12 learned how to write services by looking 11 at the source code for the stock Email app 10 that is included with Android.
The general 9 idea is that you override the Service class, and 8 set up alarms to activate your service. Unlike 7 daemons and Windows services, Android services 6 aren't always running - they start up (usually 5 when activated by an alarm), perform work, then 4 shut down. In some cases, you may need to 3 acquire a partial wake lock to keep the service going until 2 it completes the task - otherwise, Android 1 may kill your service prematurely.
If you want to build a cronjob runner then 13 what you want is a Service:
A Service is an application 12 component that can perform long-running 11 operations in the background and does not 10 provide a user interface. Another application 9 component can start a service and it will 8 continue to run in the background even if 7 the user switches to another application. Additionally, a 6 component can bind to a service to interact 5 with it and even perform interprocess communication 4 (IPC). For example, a service might handle 3 network transactions, play music, perform 2 file I/O, or interact with a content provider, all 1 from the background.
I have a feeling this may help: http://www.tutorialforandroid.com/2009/01/using-handler-in-android.html
0
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.