How To Use Service To Update Sqlite Database In Android
I am able to update sqlite database and retrieving the data through a thread from my Activity. But i need to update the database using Service, which will update the database in ev
Solution 1:
Create a timer object on your service class
Timer timer=new Timer();
On on create
@OverridepublicvoidonCreate()
{
super.onCreate();
timer.schedule(newDelayedTask(),300, 300000);// 300000 is 5min
}
Class DelayedTask
privateclassDelayedTaskextendsTimerTask
{
@Overridepublicvoidrun() {
Log.i(tag,"Timer Task executing");
// code for updating sqlite database
}
}
Solution 2:
This question if very general. To see how to use a service, take at look at this.
If you want your service to be woken every five minutes, you should use the AlarmManager.
If you have a specific question along the way, post that.
Post a Comment for "How To Use Service To Update Sqlite Database In Android"