Java and Android

// Snippet of service class called at set intervals to run internal Updater class
public class DownloaderService extends Service {

private DataBaseHelper dbHelper ;
private Updater updater ;

public void onCreate()
updater = new Updater();
dbHelper = new DataBaseHelper(this);

// thread class to call external API and update database
private class Updater extends Thread

public Updater()

// Overrides the threads run class
// Calls the execution method of the RestClient class which in turn uses the RequestMethod
// Database helper class is called to update database
public void run()
final String UPDATE_URL = "http://www.URL_TO_THE API" ;
RestClient restClient = new RestClient(UPDATE_URL);
restClient.Execute(RequestMethod.GET, null);
catch (Exception e)
dbHelper = new DataBaseHelper(getApplicationContext());

Example OneExample TwoExample Three

Updating from an external API

Example One:

This is a snippet of a class that extends from the service class. This is to periodically update the internal database with data that has been sent to an external database from other devices.

An internal thread class is included that runs in the background.

Example Two:

This executes the calling of the external API and parses the returned data into a JSONArray.

From the service class shown in example one the database class is called and the returned data is input into the internal database.

Example Three:

A single column of multiple rows is updated in the SQLite database of the device.

This format can also be applied to mySQL.