How to use service into another service in Android

Viewed 23

In my application I have 2 service and I want bind one of this services into another service!
I write below codes but after run application show me error!
In Service #1 I used below codes for bind Service #2 :

    private ServiceConnection serviceConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            //Get the service instance
            FloatingControlService.ServiceBinder binder = (FloatingControlService.ServiceBinder) service;
            floatingControlService = binder.getService();
            isBound = true;
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            floatingControlService = null;
            isBound = false;
        }
    };

             @Override
    public int onStartCommand(Intent intent, int flags, int startId) {   

    bindService(floatingControlsIntent, serviceConnection, BIND_AUTO_CREATE);

            //Set the state of the recording
            if (isBound)
                floatingControlService.setRecordingState(ConstKeys.RecordingState.RECORDING);

}

Show me error for this line : bindService(floatingControlsIntent, serviceConnection, BIND_AUTO_CREATE);

LogCat error :

6229-6229/com.myapp E/ActivityThread: Service com.testady.tester.services.RecorderService has leaked ServiceConnection com.testady.tester.services.RecorderService$2@9501e13 that was originally bound here
    android.app.ServiceConnectionLeaked: Service com.testady.tester.services.RecorderService has leaked ServiceConnection com.testady.tester.services.RecorderService$2@9501e13 that was originally bound here
        at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:2092)
        at android.app.LoadedApk.getServiceDispatcherCommon(LoadedApk.java:1964)
        at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:1943)
        at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:2045)
        at android.app.ContextImpl.bindService(ContextImpl.java:1976)
        at android.content.ContextWrapper.bindService(ContextWrapper.java:829)
        at com.myapp.services.RecorderService.startRecording(RecorderService.java:241)
        at com.myapp.services.RecorderService.onStartCommand(RecorderService.java:162)
        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5092)
        at android.app.ActivityThread.access$2200(ActivityThread.java:310)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2319)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.app.ActivityThread.main(ActivityThread.java:8663)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

How can I fix it?

How can I fix it?

0 Answers
Related