本文整理匯總了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;
}