0

I am developing an app with a service. I try to import the app from Android 4.4 to Android 5 but I cannot bind to my service.

The service is registered in the AndroidManifest.

In my Application class,I start the service with :

startService(new Intent(this, MyService.class))

Now I am trying to connect to it in my Activity with :

bindService(new Intent(MyService.class.getName()), connection, Context.BIND_AUTO_CREATE)

but I always get an IllegalArgumentException in this line and I do not know what to do.

Here is my logact error-

PlayerActivity:java.lang.RuntimeException: Unable to resume activity {at.alex.player/at.alex.player.activities.PlayerActivity}: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=at.alex.player.lib.soap.MyService }
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3521)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3552)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2872)
at android.app.ActivityThread.access$900(ActivityThread.java:181)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1476)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6134)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=at.alex.player.lib.soap.MyService }
at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:2051)
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:2159)
at android.app.ContextImpl.bindService(ContextImpl.java:2137)
at android.content.ContextWrapper.bindService(ContextWrapper.java:559)
at         at.alex.player.activities.PlayerActivity.onResume(PlayerActivity.java:815)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1255)
at android.app.Activity.performResume(Activity.java:6495)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3510)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3552)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2872)
at android.app.ActivityThread.access$900(ActivityThread.java:181)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1476)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6134)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Aditi Parikh
  • 1,522
  • 3
  • 13
  • 34
lex
  • 77
  • 2
  • 9

1 Answers1

0

I do not know why you changed your Intent. Try this:

bindService(new Intent(this, MyService.class), connection, Context.BIND_AUTO_CREATE)

You need to use an explicit Intent to bind, starting with Android 5.0, and if it is your own service, new Intent(this, MyService.class) is the simplest way to get an explicit Intent for it.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Great, the error is gone but I do not get a connection to register my Callback. I have noticed that bindService() returns false. – lex Sep 23 '15 at 14:00
  • @lexi: You may wish to ask a separate Stack Overflow question, where you supply your manifest, your service implementation, and the code where you are binding to it, in hopes that somebody can help you with that new problem. – CommonsWare Sep 23 '15 at 14:02