Code example for ContextWrapper

Methods: setClass, bindService, startService

0
    public static ServiceToken bindToService(Activity context, ServiceConnection callback) {
        Activity realActivity = context.getParent();
        if (realActivity == null) {
            realActivity = context;
        } 
        ContextWrapper cw = new ContextWrapper(realActivity);
        cw.startService(new Intent(cw, DlnaMediaControlService.class));
        ServiceBinder sb = new ServiceBinder(callback);
        if (cw.bindService((new Intent()).setClass(cw, DlnaMediaControlService.class), sb, 0)) {
            sConnectionMap.put(cw, sb);
            return new ServiceToken(cw);
        } 
        Log.e(TAG, "Failed to bind to service");
        return null; 
    } 
 
    public static void unbindFromService(ServiceToken token) {
        if (token == null) {
            Log.e(TAG, "Trying to unbind with null token");
            return; 
        }