Example usage for android.content ServiceConnection onServiceConnected

List of usage examples for android.content ServiceConnection onServiceConnected

Introduction

In this page you can find the example usage for android.content ServiceConnection onServiceConnected.

Prototype

void onServiceConnected(ComponentName name, IBinder service);

Source Link

Document

Called when a connection to the Service has been established, with the android.os.IBinder of the communication channel to the Service.

Usage

From source file:android.content.ContextImpl.java

@Override
public boolean bindService(Intent intent, ServiceConnection conn, int flags) {
    System.out.println("ContexImpl: bind service " + intent.getComponentName().getClassName());

    System.out.println("ContexImpl: start service " + intent.getComponentName().getClassName());

    ServiceDelegator delegator = intentReslover.getServiceDelegator(intent.getComponentName().getClassName());
    String bindingComponent = name.getClassName();
    intentReslover.addBindingRecord(intent.getComponentName().getClassName(), bindingComponent);
    conn.onServiceConnected(intent.getComponentName(), delegator.onBind(intent));
    return true;/*from   ww  w . j a v  a2s. co m*/
}

From source file:edu.umich.oasis.sandbox.SandboxContext.java

@Override
public boolean bindService(Intent service, ServiceConnection conn, int flags) {
    ComponentName component = service.getComponent();
    if (component != null && component.getPackageName().equals(BuildConfig.APPLICATION_ID)
            && component.getClassName().equals(OASISService.class.getName())) {
        IBinder rootBinder = mRootService.asBinder();
        ComponentName oldMapping;// w  ww.j ava2  s  . co  m
        synchronized (mBoundServices) {
            oldMapping = mBoundServices.put(conn, component);
        }
        if (oldMapping == null) {
            conn.onServiceConnected(component, rootBinder);
        }
        return true;
    }
    return super.bindService(service, conn, flags);
}

From source file:edu.umich.flowfence.sandbox.SandboxContext.java

@Override
public boolean bindService(Intent service, ServiceConnection conn, int flags) {
    ComponentName component = service.getComponent();
    if (component != null && component.getPackageName().equals(BuildConfig.APPLICATION_ID)
            && component.getClassName().equals(FlowfenceService.class.getName())) {
        IBinder rootBinder = mRootService.asBinder();
        ComponentName oldMapping;//from ww w.java2  s.co  m
        synchronized (mBoundServices) {
            oldMapping = mBoundServices.put(conn, component);
        }
        if (oldMapping == null) {
            conn.onServiceConnected(component, rootBinder);
        }
        return true;
    }
    return super.bindService(service, conn, flags);
}

From source file:android.content.ScopedContextImpl.java

@Override
public boolean bindService(final Intent intent, final ServiceConnection conn, int flags) {
    System.out.println("ContexImpl: bind service " + intent.getComponentName().getClassName());

    System.out.println("ContexImpl: start service " + intent.getComponentName().getClassName());

    ImmortalMemory.instance().executeInArea(new Runnable() {

        public void run() {
            try {
                ScopedMemory ma = intentReslover.getServiceScope(intent.getComponentName().getClassName());
                String bindingComponent = name.getClassName();
                intentReslover.addBindingRecord(intent.getComponentName().getClassName(), bindingComponent);
                ma.enter(new Runnable() {

                    public void run() {
                        try {
                            ScopedServiceDelegator d = (ScopedServiceDelegator) ((ScopedMemory) RealtimeThread
                                    .getCurrentMemoryArea()).getPortal();
                            d.setIntnet(intent);
                            d.onBind(intent);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }/*  w  w w . j  a  va 2  s. co  m*/
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    IMessenger mediator = new ScopedMessengerMediator(intent.getComponentName().getClassName());
    conn.onServiceConnected(intent.getComponentName(), mediator.asBinder());
    return true;
}