Sunday, 3 April 2011

Android Service - Bounded - Service example

package se.kth.wireless.cosem;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;

public class LocalService extends Service{

    /**
     * Class for clients to access. Because we know this service always
     * runs in the same process as its clients, we don't need to deal with
     * IPC
     */
  
    public class LocalBinder extends Binder {
        LocalService getService() {
            return LocalService.this;
        }
    }
  
    //This is the object that receives interactions from clients. See
    //RemoteService for a more complete example
    private final IBinder mBinder = new LocalBinder();
  
    @Override
    public IBinder onBind(Intent intent) {
        return mBinder;
    }
}

No comments:

Post a Comment