Thanks Dianne.

I followed the same examples for reference. But I am encountering some
problem while using multiple ServiceConnections (one for each other
application's service) in my main FragmentActivity. Inside my main
class, I implement the ServiceConnection interface in a inner class,
and use multiple instances of this while binding all the services.
In doing so, the onBind() function of my services is called
successfully, but the onServiceConnected() callback function is NEVER
called and the application crashes.

Just to test my other parts such as Services in other application,
using 'single' ServiceConnection as mentioned in the reference example
works completely fine and I can communicate bidirectionally in that
case. So the problem seems to be something in multiple
ServiceConnections related part in my implementation, but I couldn't
figure it out.

Could you help me if you could help in letting me know what I might be
doing wrong?

--------------
The error log of the crash is as follows:

I/MessengerService1( 1849):  onBind() called...
D/AndroidRuntime( 2474): Shutting down VM
W/dalvikvm( 2474): threadid=1: thread exiting with uncaught exception
(group=0x40015560)
E/AndroidRuntime( 2474): FATAL EXCEPTION: main
E/AndroidRuntime( 2474): java.lang.NullPointerException
E/AndroidRuntime( 2474):        at android.app.LoadedApk
$ServiceDispatcher.doConnected(LoadedApk.java:1064)
E/AndroidRuntime( 2474):        at android.app.LoadedApk$ServiceDispatcher
$RunConnection.run(LoadedApk.java:1081)
E/AndroidRuntime( 2474):        at
android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 2474):        at
android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 2474):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 2474):        at
android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime( 2474):        at
java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2474):        at
java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 2474):        at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 2474):        at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 2474):        at dalvik.system.NativeStart.main(Native
Method)


--------------
// Implementation from reference example for single service connection
private ServiceConnection mConnection = new ServiceConnection()
        {
                public void onServiceConnected(ComponentName className, IBinder
service)
                {//...}
        }

--------------

//My implementation details are as follows

public class SConnection implements ServiceConnection
        {
                private Messenger messenger = null;
                private boolean bIsBound = false;

                public void onServiceConnected(ComponentName className, IBinder
service) {
                        Log.i(TAG, "\n\n onServiceConnected() called... 
ComponentName: " +
className.toString());
                        //some definition
                }

                public void onServiceDisconnected(ComponentName className) {
                     //some definition}

                public boolean isBound() {
                     //some definition}

                public void sendMessage(Message message) {
                     //some definition}
        };


--------------
serviceConnections = new SConnection[4];

// Get responsive services class info through android packagemanager
API and get the corresponding ResolveInfo
// for index: 0-3, bind all the services as found above
bindService(new Intent(resolveInfo.serviceInfo.name),
serviceConnections[index], Context.BIND_AUTO_CREATE);

-----
If any more info is required please let me know.




-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to