Example usage for android.content ContextWrapper startService

List of usage examples for android.content ContextWrapper startService

Introduction

In this page you can find the example usage for android.content ContextWrapper startService.

Prototype

@Override
    public ComponentName startService(Intent service) 

Source Link

Usage

From source file:Main.java

private static void bindToService(Intent intent, Context context, ServiceConnection callback) {
    Context realActivity = context.getApplicationContext();
    if (realActivity == null) {
        realActivity = context;/*  w ww. jav a2  s .  c  o  m*/
    }
    ContextWrapper cw = new ContextWrapper(realActivity);
    cw.startService(intent);
    cw.bindService(intent, callback, Context.BIND_AUTO_CREATE);
}

From source file:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java

public static ServiceToken bindToService(Activity context, ServiceConnection callback) {
    Activity realActivity = context.getParent();
    if (realActivity == null) {
        realActivity = context;/*from   ww w  .  j  av a 2 s. c  o  m*/
    }
    ContextWrapper cw = new ContextWrapper(realActivity);
    cw.startService(new Intent(cw, MediaPlaybackService.class));
    ServiceBinder sb = new ServiceBinder(callback);
    if (cw.bindService((new Intent()).setClass(cw, MediaPlaybackService.class), sb, 0)) {
        sConnectionMap.put(cw, sb);
        return new ServiceToken(cw);
    }
    Log.e("Music", "Failed to bind to service");
    return null;
}

From source file:com.andrew.apollo.utils.MusicUtils.java

/**
 * @param context The {@link Context} to use
 * @param callback The {@link ServiceConnection} to use
 * @return The new instance of {@link ServiceToken}
 *///www .ja  va  2  s.  c om
public static ServiceToken bindToService(final Context context, final ServiceConnection callback) {
    Activity realActivity = ((Activity) context).getParent();
    if (realActivity == null) {
        realActivity = (Activity) context;
    }
    final ContextWrapper contextWrapper = new ContextWrapper(realActivity);
    contextWrapper.startService(new Intent(contextWrapper, MusicPlaybackService.class));
    final ServiceBinder binder = new ServiceBinder(callback);
    if (contextWrapper.bindService(new Intent().setClass(contextWrapper, MusicPlaybackService.class), binder,
            0)) {
        mConnectionMap.put(contextWrapper, binder);
        return new ServiceToken(contextWrapper);
    }
    return null;
}