Java Code Examples for android.content.ServiceConnection
The following code examples are extracted from open source projects. You can click to
vote up the examples that are useful to you.
Example 1
From project androidtracks, under directory /src/org/sfcta/cycletracks/.
Source file: RecordingActivity.java

void cancelRecording(){ Intent rService=new Intent(this,RecordingService.class); ServiceConnection sc=new ServiceConnection(){ public void onServiceDisconnected( ComponentName name){ } public void onServiceConnected( ComponentName name, IBinder service){ IRecordService rs=(IRecordService)service; rs.cancelRecording(); unbindService(this); } } ; bindService(rService,sc,Context.BIND_AUTO_CREATE); }
Example 2
From project Android_1, under directory /SharedNotepad/src/com/example/android/notepad/.
Source file: NoteEditor.java

@Override protected void onStart(){ super.onStart(); Context context=getApplicationContext(); final LocationManager locationManager=(LocationManager)context.getSystemService(Context.LOCATION_SERVICE); Intent sharedNotepadIntent=new Intent(); sharedNotepadIntent.setComponent(new ComponentName(context,"com.example.android.sharedobjectservice.SharedObjectContainerService")); ServiceConnection serviceConnection=new ServiceConnection(){ @Override public void onServiceConnected( ComponentName name, IBinder service){ System.out.println("onServiceConnected name=" + name + ",service="+ service); String clientId=android.provider.Settings.Secure.getString(getContentResolver(),android.provider.Settings.Secure.ANDROID_ID); if (clientId == null) clientId="simulator-" + IDFactory.getDefault().createGUID().getName(); System.out.println("clientID=" + clientId); sharedNotepadClient=new SharedNotepadClient((ISharedObjectContainerService)service,clientId,"android.slewis",mOriginalContent,sharedNotepadListener,locationManager); try { sharedNotepadClient.connect(CONNECT_TARGET); } catch ( ContainerConnectException e) { e.printStackTrace(); } try { sharedNotepadClient.sendUpdate("original note content: " + mOriginalContent); } catch ( IOException e) { e.printStackTrace(); } } @Override public void onServiceDisconnected( ComponentName name){ System.out.println("onServiceDisconnected name=" + name); sharedNotepadClient.close(); sharedNotepadClient=null; } } ; boolean bindResult=context.bindService(sharedNotepadIntent,serviceConnection,BIND_AUTO_CREATE); if (!bindResult) System.err.println("binding to SharedObjectContainerService failed"); }
Example 3
From project android-client_1, under directory /src/com/googlecode/asmack/sync/.
Source file: LoginTestThread.java

/** * Bind to the xmpp service. */ private final synchronized void bindService(){ if (serviceConnection == null) { serviceConnection=new ServiceConnection(){ public void onServiceDisconnected( ComponentName name){ } public void onServiceConnected( ComponentName name, IBinder binder){ service=IBuddycloudService.Stub.asInterface(binder); } } ; } authenticatorActivity.bindService(new Intent(IBuddycloudService.class.getName()),serviceConnection,Context.BIND_AUTO_CREATE); }
Example 4
From project android-vpn-settings, under directory /src/com/android/settings/vpn/.
Source file: AuthenticationActor.java

private void connect(final String username,final String password){ mVpnManager.startVpnService(); ServiceConnection c=new ServiceConnection(){ public void onServiceConnected( ComponentName className, IBinder service){ try { boolean success=IVpnService.Stub.asInterface(service).connect(mProfile,username,password); if (!success) { Log.d(TAG,"~~~~~~ connect() failed!"); } else { Log.d(TAG,"~~~~~~ connect() succeeded!"); } } catch ( Throwable e) { Log.e(TAG,"connect()",e); broadcastConnectivity(VpnState.IDLE,VpnManager.VPN_ERROR_CONNECTION_FAILED); } finally { mContext.unbindService(this); } } public void onServiceDisconnected( ComponentName className){ checkStatus(); } } ; if (!bindService(c)) { broadcastConnectivity(VpnState.IDLE,VpnManager.VPN_ERROR_CONNECTION_FAILED); } }
Example 5
From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/vpn/.
Source file: AuthenticationActor.java

private void connect(final String username,final String password){ mVpnManager.startVpnService(); ServiceConnection c=new ServiceConnection(){ public void onServiceConnected( ComponentName className, IBinder service){ try { boolean success=IVpnService.Stub.asInterface(service).connect(mProfile,username,password); if (!success) { Log.d(TAG,"~~~~~~ connect() failed!"); } else { Log.d(TAG,"~~~~~~ connect() succeeded!"); } } catch ( Throwable e) { Log.e(TAG,"connect()",e); broadcastConnectivity(VpnState.IDLE,VpnManager.VPN_ERROR_CONNECTION_FAILED); } finally { mContext.unbindService(this); } } public void onServiceDisconnected( ComponentName className){ checkStatus(); } } ; if (!bindService(c)) { broadcastConnectivity(VpnState.IDLE,VpnManager.VPN_ERROR_CONNECTION_FAILED); } }
Example 6
From project AsmackService, under directory /src/com/googlecode/asmack/sync/.
Source file: LoginTestThread.java

/** * Bind to the xmpp service. */ private final synchronized void bindService(){ if (serviceConnection == null) { serviceConnection=new ServiceConnection(){ public void onServiceDisconnected( ComponentName name){ } public void onServiceConnected( ComponentName name, IBinder binder){ service=IXmppTransportService.Stub.asInterface(binder); } } ; } authenticatorActivity.bindService(new Intent(IXmppTransportService.class.getName()),serviceConnection,Context.BIND_AUTO_CREATE); }
Example 7
From project ChkBugReport, under directory /examples/testapp/src/com/sonymobile/chkbugreport/testapp/.
Source file: AIDLDeadlock.java

/** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); System.out.println(">>> onCreate"); Intent service=new Intent(this,AIDLDeadlockService.class); ServiceConnection connection=new ServiceConnection(){ @Override public void onServiceDisconnected( ComponentName name){ } @Override public void onServiceConnected( ComponentName name, IBinder service){ mService=IDeadlock.Stub.asInterface(service); System.out.println(">>> onService Connected"); try { synchronized (LOCK1) { mService.setCallback(mCB); mService.doStep1(); } } catch ( RemoteException e) { e.printStackTrace(); } } } ; bindService(service,connection,BIND_AUTO_CREATE); }
Example 8
From project lastfm-android, under directory /app/src/fm/last/android/adapter/.
Source file: LastFMStreamAdapter.java

/** * Binds to the player service, refreshes our list, then unbinds the player service */ public void updateNowPlaying(){ LastFMApplication.getInstance().bindService(new Intent(LastFMApplication.getInstance(),fm.last.android.player.RadioPlayerService.class),new ServiceConnection(){ public void onServiceConnected( ComponentName comp, IBinder binder){ player=IRadioPlayer.Stub.asInterface(binder); notifyDataSetChanged(); LastFMApplication.getInstance().unbindService(this); } public void onServiceDisconnected( ComponentName comp){ player=null; } } ,Context.BIND_AUTO_CREATE); }
Example 9
From project open_robot, under directory /Android/TouchControl/src/com/robot/open/.
Source file: TouchControl.java

private void initServerServiceConnection(){ serverConnection=new ServiceConnection(){ public void onServiceConnected( ComponentName className, IBinder service){ serverService=((ServerService.ServerBinder)service).getService(); Toast.makeText(currentContext(),R.string.server_service_connected,Toast.LENGTH_SHORT).show(); makeServerConnection(); } public void onServiceDisconnected( ComponentName className){ serverService=null; Toast.makeText(currentContext(),R.string.server_service_disconnected,Toast.LENGTH_SHORT).show(); } } ; }
Example 10
public void connect(final VpnProfile p){ Log.i(TAG,"connect to: " + p); p.preConnect(); final VpnProfile cp=p.dulicateToConnect(); getVpnMgr().startVpnService(); ServiceConnection c=new ServiceConnection(){ @Override public void onServiceConnected( final ComponentName className, final IBinder service){ try { boolean success=getVpnSrv().connect(service,cp); if (!success) { Log.d(TAG,"~~~~~~ connect() failed!"); broadcastConnectivity(cp.getName(),VpnState.IDLE,VPN_ERROR_CONNECTION_FAILED); } else { Log.d(TAG,"~~~~~~ connect() succeeded!"); } } catch ( Throwable e) { Log.e(TAG,"connect()",e); broadcastConnectivity(cp.getName(),VpnState.IDLE,VPN_ERROR_CONNECTION_FAILED); } finally { context.unbindService(this); } } @Override public void onServiceDisconnected( final ComponentName className){ Log.e(TAG,"onServiceDisconnected"); checkStatus(); } } ; if (!getVpnMgr().bindVpnService(c)) { Log.e(TAG,"bind service failed"); broadcastConnectivity(cp.getName(),VpnState.IDLE,VPN_ERROR_CONNECTION_FAILED); } }
Example 11
From project agit, under directory /agit/src/main/java/com/madgag/agit/ssh/.
Source file: AndroidAuthAgentProvider.java

private void bindSshAgentTo(Context context){ Intent intent=new Intent("org.openintents.ssh.BIND_SSH_AGENT_SERVICE"); intent.setComponent(preferredAuthAgentComponentNameProvider.get()); context.bindService(intent,new ServiceConnection(){ public void onServiceDisconnected( ComponentName name){ Log.i(TAG,"onServiceDisconnected() : Lost " + authAgent); authAgent=null; } public void onServiceConnected( ComponentName name, IBinder binder){ Log.i(TAG,"onServiceConnected() : componentName=" + name + " binder="+ binder); authAgent=AndroidAuthAgent.Stub.asInterface(binder); signalAuthAgentBound(); } } ,BIND_AUTO_CREATE); Log.i(TAG,"made request using context " + context + " to bind to the SSH_AGENT_SERVICE"); }
Example 12
From project apps-for-android, under directory /BTClickLinkCompete/src/net/clc/bt/.
Source file: Connection.java

public Connection(Context ctx,OnConnectionServiceReadyListener ocsrListener){ mOnConnectionServiceReadyListener=ocsrListener; mContext=ctx; mPackageName=ctx.getPackageName(); mServiceConnection=new ServiceConnection(){ public void onServiceConnected( ComponentName name, IBinder service){ synchronized (mStartLock) { mIconnection=IConnection.Stub.asInterface(service); mStarted=true; if (mOnConnectionServiceReadyListener != null) { mOnConnectionServiceReadyListener.OnConnectionServiceReady(); } } } public void onServiceDisconnected( ComponentName name){ synchronized (mStartLock) { try { mStarted=false; mIconnection.unregisterCallback(mPackageName); mIconnection.shutdown(mPackageName); } catch ( RemoteException e) { Log.e(TAG,"RemoteException in onServiceDisconnected",e); } mIconnection=null; } } } ; Intent intent=new Intent("com.google.intent.action.BT_ClickLinkCompete_SERVICE"); intent.addCategory("com.google.intent.category.BT_ClickLinkCompete"); mContext.bindService(intent,mServiceConnection,Context.BIND_AUTO_CREATE); }
Example 13
From project gobandroid, under directory /src/org/ligi/gobandroid_hd/logic/.
Source file: GnuGoMover.java

public GnuGoMover(Activity activity,GoGame game,boolean playing_black,boolean playing_white,byte level){ this.application=activity.getApplication(); this.level=level; this.playing_black=playing_black; this.playing_white=playing_white; this.game=game; if (playing_black || playing_white) { conn=new ServiceConnection(){ @Override public void onServiceConnected( ComponentName name, IBinder service){ gnu_service=IGnuGoService.Stub.asInterface(service); try { Log.i("Service bound " + gnu_service.processGTP("test")); } catch ( RemoteException e) { } } @Override public void onServiceDisconnected( ComponentName name){ Log.i("Service unbound "); } } ; application.bindService(new Intent(intent_action_name),conn,Context.BIND_AUTO_CREATE); mover_thread=new Thread(this); mover_thread.start(); } }
Example 14
From project GradeCalculator-Android, under directory /GradeCalculator/src/com/jetheis/android/grades/billing/googleplay/.
Source file: GooglePlayBillingWrapper.java

public GooglePlayBillingWrapper(Context context){ mContext=context; mOnReadyListeners=new HashSet<OnBillingReadyListener>(); mOnPurchaseStateChangedListeners=new HashSet<OnPurchaseStateChangedListener>(); mContext.startService(new Intent(mContext,GooglePlayBillingService.class)); mConnection=new ServiceConnection(){ @Override public void onServiceConnected( ComponentName name, IBinder service){ mBoundService=((GooglePlayBillingService.GooglePlayBillingBinder)service).getService(); mBoundService.checkIsBillingSupported(new OnGooglePlayBillingSupportResultListener(){ @Override public void onGooglePlayBillingSupportResultFound( boolean billingSupported){ if (billingSupported) { Log.i(Constants.TAG,"Google Play billing ready"); for ( OnBillingReadyListener listener : mOnReadyListeners) { listener.onBillingReady(); } } else { Log.i(Constants.TAG,"Google Play billing is not supported"); for ( OnBillingReadyListener listener : mOnReadyListeners) { listener.onBillingNotSupported(); } } } } ); } @Override public void onServiceDisconnected( ComponentName name){ mBoundService=null; } } ; mContext.bindService(new Intent(context,GooglePlayBillingService.class),mConnection,Context.BIND_AUTO_CREATE); }
Example 15
From project GSM-Signal-Tracking-, under directory /gpstracker/src/nl/sogeti/android/gpstracker/logger/.
Source file: GPSLoggerServiceManager.java

/** * Means by which an Activity lifecycle aware object hints about binding and unbinding * @param onServiceConnected Run on main thread after the service is bound */ public void startup(Context context,final Runnable onServiceConnected){ synchronized (mStartLock) { if (!mBound) { mOnServiceConnected=onServiceConnected; mServiceConnection=new ServiceConnection(){ public void onServiceConnected( ComponentName className, IBinder service){ synchronized (mStartLock) { GPSLoggerServiceManager.this.mGPSLoggerRemote=IGPSLoggerServiceRemote.Stub.asInterface(service); mBound=true; } if (mOnServiceConnected != null) { mOnServiceConnected.run(); mOnServiceConnected=null; } } public void onServiceDisconnected( ComponentName className){ synchronized (mStartLock) { mBound=false; } } } ; context.bindService(new Intent(Constants.SERVICENAME),this.mServiceConnection,Context.BIND_AUTO_CREATE); } else { Log.w(TAG,"Attempting to connect whilst already connected"); } } }
Example 16
From project npr-android-app, under directory /src/org/npr/android/news/.
Source file: ListenView.java

public void attachToPlaybackService(){ Intent serviceIntent=new Intent(getContext(),PlaybackService.class); conn=new ServiceConnection(){ @Override public void onServiceConnected( ComponentName name, IBinder service){ player=((PlaybackService.ListenBinder)service).getService(); } @Override public void onServiceDisconnected( ComponentName name){ Log.w(LOG_TAG,"DISCONNECT"); player=null; } } ; getContext().getApplicationContext().startService(serviceIntent); getContext().getApplicationContext().bindService(serviceIntent,conn,0); getContext().registerReceiver(changeReceiver,new IntentFilter(PlaybackService.SERVICE_CHANGE_NAME)); getContext().registerReceiver(updateReceiver,new IntentFilter(PlaybackService.SERVICE_UPDATE_NAME)); getContext().registerReceiver(closeReceiver,new IntentFilter(PlaybackService.SERVICE_CLOSE_NAME)); }
Example 17
From project ohmagePhone, under directory /src/org/ohmage/triggers/types/location/.
Source file: LocTrigService.java

private void startMotionDetection(){ Log.i(TAG,"LocTrigService: Starting motion detection..."); mWifiGPSServConn=new ServiceConnection(){ @Override public void onServiceDisconnected( ComponentName name){ Log.i(TAG,"LocTrigService: WifiGPS disconnected"); mWiFiGPSServ=null; } @Override public void onServiceConnected( ComponentName name, IBinder service){ Log.i(TAG,"LocTrigService: WifiGPS connected"); mWiFiGPSServ=IWiFiGPSLocationService.Stub.asInterface(service); registerMotionDetectionCB(); } } ; mAccelServConn=new ServiceConnection(){ @Override public void onServiceDisconnected( ComponentName name){ Log.i(TAG,"LocTrigService: AccelService disconnected"); mAccelServ=null; } @Override public void onServiceConnected( ComponentName name, IBinder service){ Log.i(TAG,"LocTrigService: AccelService connected"); mAccelServ=IAccelService.Stub.asInterface(service); registerMotionDetectionCB(); } } ; connectToRemoteServices(); }
Example 18
From project Ohmage_Phone, under directory /src/org/ccnx/android/ccnlib/.
Source file: CCNxWrapper.java

protected void bindService(){ sConn=new ServiceConnection(){ public void onServiceConnected( ComponentName name, IBinder binder){ Log.d(TAG," Service Connected"); synchronized (iServiceLock) { iService=ICCNxService.Stub.asInterface(binder); try { iService.registerStatusCallback(_cb); SERVICE_STATUS st=SERVICE_STATUS.fromOrdinal(iService.getStatus()); Log.i(TAG,"bindService sets status: " + st); setStatus(st); } catch ( RemoteException e) { e.printStackTrace(); } } issueCallback(); } public void onServiceDisconnected( ComponentName name){ Log.i(TAG," Service Disconnected"); synchronized (iServiceLock) { iService=null; } } } ; _ctx.bindService(getBindIntent(),sConn,Context.BIND_AUTO_CREATE); }
Example 19
From project vlc-android, under directory /vlc-android/src/org/videolan/vlc/android/.
Source file: AudioServiceController.java

private AudioServiceController(Context c){ if (c != null) mContext=c; else mContext=MainActivity.getInstance(); mAudioPlayer=new ArrayList<AudioPlayer>(); mAudioServiceConnection=new ServiceConnection(){ @Override public void onServiceDisconnected( ComponentName name){ Log.d(TAG,"Service Disconnected"); mAudioServiceBinder=null; } @Override public void onServiceConnected( ComponentName name, IBinder service){ Log.d(TAG,"Service Connected"); mAudioServiceBinder=IAudioService.Stub.asInterface(service); try { mAudioServiceBinder.addAudioCallback(mCallback); } catch ( RemoteException e) { Log.e(TAG,"remote procedure call failed: addAudioCallback()"); } updateAudioPlayer(); } } ; }
Example 20
From project adg-android, under directory /src/com/analysedesgeeks/android/.
Source file: MusicUtils.java

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; }
Example 21
From project android-marvin, under directory /marvin/src/main/java/de/akquinet/android/marvin/.
Source file: AndroidTestCase.java

@Override protected void tearDown() throws Exception { this.activityMonitor.stop(); getInstrumentation().waitForIdleSync(); for ( StartedActivity activity : activityMonitor.getStartedActivities()) { if (!shallLeaveRunning(activity.getActivity()) && !activity.getActivity().isFinishing()) { try { Log.i(getClass().getName(),"Finishing activity: " + activity.getActivity().getClass().getName()); activity.getActivity().finish(); getInstrumentation().waitForIdleSync(); Thread.sleep(1000); getInstrumentation().waitForIdleSync(); } catch ( Exception e) { Log.e(getClass().getName(),"Problem on activity finish:",e); } } } activityMonitor.clear(); for ( ServiceConnection connection : serviceConnections.values()) { getInstrumentation().getTargetContext().unbindService(connection); } serviceConnections.clear(); getInstrumentation().waitForIdleSync(); super.tearDown(); }
Example 22
From project android-vpn-server, under directory /src/android/net/vpn/.
Source file: VpnManager.java

/** * Binds the specified ServiceConnection with the VPN service. */ public boolean bindVpnService(ServiceConnection c){ if (!mContext.bindService(new Intent(ACTION_VPN_SERVICE),c,0)) { Log.w(TAG,"failed to connect to VPN service"); return false; } else { Log.d(TAG,"succeeded to connect to VPN service"); return true; } }
Example 23
From project BSPAN---Bluetooth-Sensor-Processing-for-Android, under directory /AndroidSpineServer/src/com/t2/.
Source file: AndroidSpineServerMainActivity.java

/** * Binds this activity to a service using the service connection specified. Note that it is the responsibility of the calling party (AndroidMessageServer) to update this activities member variable, mService, when the connection to the service is complete. AndroidMessageServer can't do the bind by itself because it needs to be done by an Android activity. Also, we do it here because the AndroidMessageServer doesn't know when we are destroyed. Here we know and can unbind the service. The reason we don't simply move all of the binding here is that AndroidMessageServer needs to create it's own Messenger for the service connection. * @param mConnection A previously established service connection */ public void doBindService(ServiceConnection mConnection){ this.mConnection=mConnection; Log.i(TAG,"*****************binding **************************"); try { Intent intent2=new Intent("com.t2.biofeedback.IBioFeedbackService"); bindService(intent2,mConnection,Context.BIND_AUTO_CREATE); Log.i(TAG,"*****************binding SUCCESS**************************"); mIsBound=true; } catch ( Exception e) { Log.i(TAG,"*****************binding FAIL**************************"); Log.e(TAG,e.toString()); } }
Example 24
/** * Glue to bind to this service * @param context the client's context * @param client who to notify */ public static void bindTo(Context context,ServiceConnection client){ context=context.getApplicationContext(); Republisher conns=clients.get(context); if (conns == null) { conns=new Republisher(); conns.add(client); clients.put(context,conns); context.bindService(new Intent(context,GPSClient.class),conns,Service.BIND_AUTO_CREATE | Service.BIND_DEBUG_UNBIND); } else conns.add(client); }
Example 25
/** * Initializes the services from the loaded plugins and stores them in the pluginmap */ private void initService(List<ResolveInfo> list,Activity activity,PluginType pluginType){ for (int i=0; i < list.size(); ++i) { ResolveInfo info=list.get(i); ServiceInfo sinfo=info.serviceInfo; if (sinfo != null) { Intent serviceIntent=new Intent(); serviceIntent.setClassName(sinfo.packageName,sinfo.name); activity.startService(serviceIntent); activity.bindService(serviceIntent,(ServiceConnection)pluginType.getPluginConnection(),Context.BIND_AUTO_CREATE); checkForPendingActivity(pluginType); } } }
Example 26
From project mp3tunes-android, under directory /src/com/mp3tunes/android/.
Source file: Music.java

public static boolean bindToService(Context context,ServiceConnection callback){ context.startService(new Intent(context,Mp3tunesService.class)); ServiceBinder sb=new ServiceBinder(callback); sConnectionMap.put(context,sb); return context.bindService((new Intent()).setClass(context,Mp3tunesService.class),sb,0); }
Example 27
From project platform_packages_apps_music, under directory /src/com/android/music/.
Source file: MusicUtils.java

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; }
Example 28
From project roboject, under directory /roboject/src/main/java/de/akquinet/android/roboject/injectors/.
Source file: ServiceInjector.java

@Override public void onStop(){ state=InjectorState.STARTED; Context appContext=context.getApplicationContext(); for ( ServiceConnection connection : serviceConnections) { unbindSafely(appContext,connection); } serviceConnections.clear(); }
Example 29
From project twidere, under directory /src/org/mariotaku/twidere/util/.
Source file: ServiceUtils.java

public static ServiceToken bindToService(final Context context,final Intent intent,final ServiceConnection callback){ final ContextWrapper cw=new ContextWrapper(context); final ComponentName cn=cw.startService(intent); if (cn != null) { final ServiceUtils.ServiceBinder sb=new ServiceBinder(callback); if (cw.bindService(intent,sb,0)) { sConnectionMap.put(cw,sb); return new ServiceToken(cw); } } Log.e(LOGTAG,"Failed to bind to service"); return null; }
Example 30
public ServiceToken bindToService(ServiceConnection callback){ ContextWrapper cw=new ContextWrapper(mContext); cw.startService(new Intent(cw,MusicPlaybackService.class)); ServiceBinder sb=new ServiceBinder(callback); if (cw.bindService(new Intent(cw,MusicPlaybackService.class),sb,0)) { mConnectionMap.put(cw,sb); return new ServiceToken(cw); } Log.e("Music","Failed to bind to service"); return null; }