本文整理汇总了Java中android.content.ContextWrapper.bindService方法的典型用法代码示例。如果您正苦于以下问题:Java ContextWrapper.bindService方法的具体用法?Java ContextWrapper.bindService怎么用?Java ContextWrapper.bindService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.ContextWrapper
的用法示例。
在下文中一共展示了ContextWrapper.bindService方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bindToService
import android.content.ContextWrapper; //导入方法依赖的package包/类
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);
}
return null;
}
示例2: bindToService
import android.content.ContextWrapper; //导入方法依赖的package包/类
/**
* @param context The {@link Context} to use
* @param callback The {@link ServiceConnection} to use
* @return The new instance of {@link ServiceToken}
*/
public static ServiceToken bindToService(final Context context, final ServiceConnection callback) {
ContextWrapper contextWrapper = new ContextWrapper(context);
ServiceBinder binder = new ServiceBinder(callback);
Intent intent = new Intent().setClass(contextWrapper, UploadService.class);
if (contextWrapper.bindService(intent, binder, 0)) {
mConnectionMap.put(contextWrapper, binder);
return new ServiceToken(contextWrapper);
}
Logger.d(TAG, "bindToService, count: " + mConnectionMap.size());
return null;
}
示例3: bindToServiceWithoutStart
import android.content.ContextWrapper; //导入方法依赖的package包/类
public static ServiceToken bindToServiceWithoutStart(final Activity realActivity, final ServiceConnection callback) {
final ContextWrapper contextWrapper = new ContextWrapper(realActivity);
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;
}