I want to create an android service which is able to fetch and parse JSON data into my local database. I have already written the code for this to be done as a normal activity. But I would like to change it so that it updates the database on a regular basis. How would I go about doing this?
So far I have created a basic service but I do not know how to tie in my activity into the service or how to set the service to start up when the application is opened up.
Basic Data Service
public class DataFetcher extends Service {
private static final int POLL_PERIOD=120000;
private AtomicBoolean active=new AtomicBoolean(true);
@Override
public void onCreate() {
super.onCreate();
}
@Override
public IBinder onBind(Intent intent) {
return(null);
}
@Override
public void onDestroy() {
super.onDestroy();
}
private Runnable threadBody=new Runnable() {
public void run() {
while(active.get()) {
SystemClock.sleep(POLL_PERIOD);
}
}
};
}
Comments
Post a Comment