Esri's Geotrigger Service is replacing Geoloqi! Learn More | FAQ

Service Binding - Android SDK

If you are an advanced user, you can bind to the tracking service from your Activity and call any public methods. This may be useful if you want to trigger API calls from your application's UI. Local service binding can be easily achieved, but with great power comes great responsibility.

public void onResume() {

    // Bind to the tracking service so we can call public methods on it
    Intent intent = new Intent(this, LQService.class);
    bindService(intent, mConnection, 0);

public void onPause() {

    // Unbind from LQService
    if (mBound) {
        mBound = false;

private LQService mService;
private boolean mBound;

/** Defines callbacks for service binding, passed to bindService() */
private ServiceConnection mConnection = new ServiceConnection() {
    public void onServiceConnected(ComponentName name, IBinder service) {
        try {
            // We've bound to LocalService, cast the IBinder and get LocalService instance.
            LQBinder binder = (LQBinder) service;
            mService = binder.getService();
            mBound = true;
        } catch (ClassCastException e) {
            // Pass

    public void onServiceDisconnected(ComponentName name) {
        mBound = false;

Once the Service binding has completed you can call methods from the service instance like mService.getTracker() or mService.getSession(). These two objects are the backbone of the Geoloqi SDK and expose many useful methods. For example, once you have an instance of LQSession you can make calls to the Geoloqi REST API. Note that you should always make sure you start the tracking service explicitly before attempting to bind to it. If you bind to the tracking service using the BINDAUTOCREATE flag the service may not continue to function once your Activity has stopped.