tags:

views:

93

answers:

2

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? –

+1  A: 

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)

molnarm
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
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
A: 

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
if result return true (plz check my edit), isnt it a sign that the binded success?
Moshik
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
Yes, the ServiceConnection is null until onServiceConnected is called (as its name suggests).
molnarm
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
`bindService()` is asynchronous. You cannot do the "operation which uses IUdpListenerService" until `onServiceConnected()` is called.
CommonsWare
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
"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
Thanks.! Are you giving phone consults? I asked my team leader for consulting hours.. and suggested about u.
Moshik
Click on my name to view my profile page, which has a link to my Web site, where you can learn more.
CommonsWare