onServiceConnected never called after bindService method

后端 未结 12 656
醉话见心
醉话见心 2020-11-30 05:48

I have a particular situation: a service started by a broadcast receiver starts an activity. I want to make it possible for this activity to communicate back to the service.

12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 06:26

    I've just experienced another version of this problem, with the same symptom of onServiceConnected(...) not being called. The cause was different in my case.

    You must make sure to have a service declaration in your AndroidManifest.xml within the application tag - this was the root of the problem for me.

    
        
        
        
    
    

    There's an extra complication if you're using a separate Android library within Eclipse - adding this Service tag only seems to fix the issue if the referenced service is in the same package as the manifest; i.e. if your app is in package a.b.c and this is where AndroidManifest.xml resides, then 'YourService' must also be in package a.b.c. (manually copied from another library, if necessary) or else the tag may/will be ignored and onServiceConnected(...) still won't be called.

    This was the case for my project even though I used a suitable import statement for the Service in my code. Eclipse showed no error, so the import was correctly identifying the class from another library in the Eclipse workspace.

    HTH

提交回复
热议问题