Thank you! I have successfully implemented a background service communicating with more activities using BroadcasReceiver. In this service I start a new thread for soket communication. Now my question is: what is the best way to communicate between the newly created thread and the service (I want to send back to the service the message received from tcp server)? I have implemented the new thread class as an inner class, so I can access members and methods from service class. It is working, but it is the right way to do this?
On Sep 1, 10:05 pm, Jeremy Wadsack <[email protected]> wrote: > Probably the best path to take would be to move your thread into a > Service<http://developer.android.com/reference/android/app/Service.html>. > Then use > Intents<http://developer.android.com/guide/topics/intents/intents-filters.html>or > binding to connect activities to the service. Similarly you can have > the > service broadcast intents and use a > BroadcastReceiver<http://developer.android.com/reference/android/content/BroadcastRecei...>with > an > IntenetFilter<http://developer.android.com/guide/topics/intents/intents-filters.html>to > listen for those messages from the service. > > Have a look at the Application > Fundamentals<http://developer.android.com/guide/topics/fundamentals.html>in > the Dev Guide and the sample code that ships with the SDK for examples > of > how to do this. > > -- > Jeremy Wadsack > > > > On Sun, Aug 29, 2010 at 12:16 PM, kukukk <[email protected]> wrote: > > Hy! > > > I want to create an application to remote control my PC. For example: > > Volume (get actual volume level, increase/decrease/mute volume), > > TVtime (start/quit tvtime, get actual channel, toggle fulscreen, > > channel up/down, toggle input source, toggle aspect ratio), Amarok > > (start/quit amarok, get current song, prev/next song, play/stop/ > > pause), etc. > > The application for the PC is done (in python). > > The communication protocol used is very simple. For example: > > "volume:get_level", "volume:up", "volume:mute", etc. > > Now I'm working on the android application. What I have implemented > > till now is to create an activity, with: > > - an edittext to enter host:port > > - a button to connect/disconnect to/from server > > - the onCreate method creates a new thread for socket communication to > > send/receive messages to/from PC. > > - a textview to display information received from PC (eg. volume > > level) > > - a button to send command to PC > > I'm using handler to communicate between the tcpclient thread and the > > main activity. It is working... > > But I want to use more than 1 activity. I want to use different > > activity for every program controlled. Searching for a solution to > > transfer the thread's handler to a new activity I have found that it > > is not possible, and I have to use a service. > > So, my question is: how to send message from different activities to > > the same service, how to send message from service to the actual > > activity and how can I check in the service which is the actual > > activity? > > > Because the service is running in the same thread as the activities I > > suppose that I still have to create a new thread for socket > > communication. How can I send the data received by the socket to the > > service? > > > Thanks in advance, > > kukukk > > > PS. I hope you understand my question and sorry if it is not the right > > forum for it > > > -- > > 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]<android-developers%2Bunsubs > > [email protected]> > > For more options, visit this group at > >http://groups.google.com/group/android-developers?hl=en -- 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

