Code example for ContextWrapper

Methods: bindServicestartServicesetClass

	public static ServiceToken bindToService(final Activity context, final ServiceConnection callback) {
		Activity realActivity = context.getParent();
		if (realActivity == null) {
			realActivity = context;
		final ContextWrapper cw = new ContextWrapper(realActivity);
		cw.startService(new Intent(cw, PodcastPlaybackService.class));
		final ServiceBinder sb = new ServiceBinder(callback);
		if (cw.bindService((new Intent()).setClass(cw, PodcastPlaybackService.class), sb, 0)) {
			sConnectionMap.put(cw, sb);
			return new ServiceToken(cw);
		Log.e("Music", "Failed to bind to service");
		return null; 
	public static String makeTimeString(final Context context, final long secs) {
		final String durationformat = context.getString(
		        secs < 3600 ? R.string.durationformatshort : R.string.durationformatlong);
Experience pair programming with AI  Get Codota for Java