onServiceConnected() not called

前端 未结 7 1348
情书的邮戳
情书的邮戳 2020-12-30 01:41

I have a problem with using a background service.
I am using the service from 2 activities.

The first activity starts the Service with start

相关标签:
7条回答
  • 2020-12-30 02:11

    Add bind in manifest..

     <service
                android:name=".MyAccessibilityService"
                android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE" >
                <intent-filter>
                    <action android:name="android.accessibilityservice.AccessibilityService" />
                </intent-filter>
    
    </service>
    

    MyAccessibilityService your service name.

    0 讨论(0)
  • 2020-12-30 02:12

    I was xmarian and had the same problem and later found that i have not given proper name to that service . So the service name should be given name attribute. Which I suppose the xmarian compiler does the same thing make that entry in Android XML.

    0 讨论(0)
  • 2020-12-30 02:21

    In my case, it was because I had forgotten to instantiate the binder inside the service and so onBind returned null. I had this:

        private ServiceBinder mServiceBinder;
    

    instead of this:

        private ServiceBinder mServiceBinder = new ServiceBinder();
    
    0 讨论(0)
  • 2020-12-30 02:22

    You need to add:

    <service android:name="package.path.to.your.service.class" android:enabled="true"></service>

    in the Android manifest file.

    0 讨论(0)
  • 2020-12-30 02:27

    This is what worked for me

    Instead of

    public IBinder onBind(Intent intent) {
        return null;
    }
    

    I used

    public IBinder onBind(Intent intent) {
        return mMessenger.getBinder();
    }
    
    0 讨论(0)
  • 2020-12-30 02:29

    It happened to me just now.
    Don't forget to instantiate your binder class before the onbind return. Silly mistake, but it happens. hopefully this will help someone in the future.

    private YourBinder thisBinder;
    
    oncreate
    {
      thisBinder = new YourBinder(); //don't forget this.
    }
    
    
    public class YourBinder extends Binder
    {
    
    }
    
    public IBinder onBind(Intent intent) 
    {
      return thisBinder;
    }
    
    0 讨论(0)
提交回复
热议问题