}
}
- public static ServiceToken bindToService(Context context) {
+ public static ServiceToken bindToService(Activity context) {
return bindToService(context, null);
}
- public static ServiceToken bindToService(Context context, ServiceConnection callback) {
- ContextWrapper cw = new ContextWrapper(context);
+ 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, 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;
}
public static void unbindFromService(ServiceToken token) {
+ if (token == null) {
+ Log.e("MusicUtils", "Trying to unbind with null token");
+ return;
+ }
ContextWrapper cw = token.mWrappedContext;
ServiceBinder sb = sConnectionMap.remove(cw);
if (sb == null) {