0

after calling:

result=bindService(new Intent(IUdpListenerService.class.getName()),
            serviceConnection, Context.BIND_AUTO_CREATE);

byt debugger: result return 'true'

the onServiceConnected isn't being called.

*ill mention that the remote service is installed in diffrent apk, and is being started by the command startService(..)

Okie.. this is new thing i just found out: onServiceConnected is being triggerd, but it takes time, so what happens here.. that when i use the instance of my interface - it's still remine null, before onServiceConnected manage to be triggerd.. is that possible? –

Moshik
  • 589
  • 1
  • 5
  • 19
  • why are you adding getName() after class? – RoflcoptrException May 27 '10 at 13:50
  • honestly.. i dont know.. i took it from an example. how would u adjust it? – Moshik May 27 '10 at 13:51
  • Use `adb logcat`, DDMS, or the DDMS perspective in Eclipse and look for warnings. You will usually get a warning if Android could not identify your service to bind to it, for example. – CommonsWare May 27 '10 at 13:55
  • 1
    And if that's my example, you would need to have adjusted your service's `` to match. – CommonsWare May 27 '10 at 13:57
  • I did use.. nothing being shown after the bindService(..) being called.. and the instance of the interface, ofcourse remine null coz onServiceConnected hasnt being called.. i watch it by the debugger – Moshik May 27 '10 at 13:57

2 Answers2

3

The service needs to have an <intent-filter> with an action:

    <service android:name=".BshService">
        <intent-filter>
            <action android:name="com.commonsware.android.advservice.IScript" />
        </intent-filter>
    </service>

You can then use the action form of an Intent to bind to it:

new Intent("com.commonsware.android.advservice.IScript")

or, if your client happens to have a class or interface named IScript in the com.commonsware.android.advservice package:

new Intent(IScript.getName());
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • if result return true (plz check my edit), isnt it a sign that the binded success? – Moshik May 27 '10 at 14:28
  • Okie.. this is new thing i just found out: now onServiceConnected is being triggerd, but it takes time, so what happens here.. that the instance of my interface - when i use it, it's still remine null, before onServiceConnected manage to be trigger.. is that possible? – Moshik May 27 '10 at 14:34
  • Yes, the ServiceConnection is null until onServiceConnected is called (as its name suggests). – molnarm May 27 '10 at 14:48
  • yes.. but this operation creates sync? coz after bindservice i have operation which uses IUdpListenerService.. and it seems that it still null, ever after bindservice return TRUE – Moshik May 27 '10 at 14:57
  • `bindService()` is asynchronous. You cannot do the "operation which uses IUdpListenerService" until `onServiceConnected()` is called. – CommonsWare May 27 '10 at 15:10
  • Ohh thanks for this POINT!! you are great.. i am getting crazy here.. but please is there any standart way to solve this some how? like how will i make my operation wait for onServiceConnected() to be called?(without UI touch) – Moshik May 27 '10 at 15:11
  • "like how will i make my operation wait for onServiceConnected() to be called?" You move the code into `onServiceConnected()`. For example, you don't have a `Thread.sleep()` call in `onCreate()` waiting for somebody to click a button -- you put the code that needs to wait for a button-click into the `onClick()` method you assign to the button. Similarly, you don't wait in `onCreate()` for a bound connection -- you put the code that needs to wait for a bound connection into the `onServiceConnected()` method. – CommonsWare May 27 '10 at 15:41
  • Thanks.! Are you giving phone consults? I asked my team leader for consulting hours.. and suggested about u. – Moshik May 30 '10 at 07:03
  • Click on my name to view my profile page, which has a link to my Web site, where you can learn more. – CommonsWare May 30 '10 at 11:15
1

The Intent constructor you use takes an Action, not a class name. To start a certain service, use new Intent(<package context, e.g. this>, IUdpListenerService.class) instead.

Update: to start a Service or Activity in another package, use setComponent:

new Intent().setComponent(new ComponentName("com.remote", "com.remote.IUdpListenerService"));

(see this question for details)

Community
  • 1
  • 1
molnarm
  • 9,856
  • 2
  • 42
  • 60
  • If my remote service is in another application called remote, and under the package called com.remote, how would u adjust it? coz i tried it , and it also didnt work – Moshik May 27 '10 at 14:02
  • You want to start a service in another package? See the answer for this question: http://stackoverflow.com/questions/2209513/how-to-start-activity-in-another-application – molnarm May 27 '10 at 14:10