I am calling bindService in Service MessengerService. It is working fine. After that I call startService.
The code is exactly the same as in this link. An example of a remote message service example is http://developer.android.com/reference/android/app/Service.html except that I add startService to the action
This is the client code: Intent intnt = new Intent (context, MessengerService.class); intnt.putExtra ("msg", "String from activity to serve handler 11");
bindService(intnt, mConnection, Context.BIND_AUTO_CREATE); intnt.putExtra("msg", "String from activity to service to handler 22"); startService(intnt);
In the service code: In onStartCommand, any message that I receive in an intent that is sent to startService, I send it back to the client handler.
I get the index from the associated exception in the line mClients.get (0) .send (msg1). mClients is an array of clients connected to this service and stored during the binding process.
The code is exactly the same as in this link. An example of the remote message service example http://developer.android.com/reference/android/app/Service.html except that I add onStartCommand to the Service
@Override public int onStartCommand(Intent intent, int flags, int startId){ String str = intent.getStringExtra("msg"); Message msg1 = Message.obtain(null, MSG_STR_VALUE); Bundle data = new Bundle(); data.putString("message", str); msg1.setData(data); System.out.println(str); try { s1.acquire(); } catch (InterruptedException e1) {
raghu source share