Try using a async thread to run the "update socket method" and update your interface using
http://developer.android.com/reference/android/app/Activity.html#runOnUiThread(java.lang.Runnable) 2011/9/8 giangiammy <giangia...@gmail.com>: > Hi all, > > I have an activity updating the GUI with data coming from a socket. > > In my activity I implemented an Handler: > > int REFRESH = 1; > final Handler hRefresh = new Handler(){ > @Override > public void handleMessage(Message msg) { > Integer i1; > Integer i2; > i1 = msg.arg1; > i2 = msg.arg2; > > ... update a widget (in my example a button background) > > } > }; > > > Then I start a thread polling the socket for new data and I define a Map > with some function, which are called depending on the incoming data: > > allServerActions.put( > ami.serverId, > new IntIntFunction() { > public int function(int i1, int i2) { > > Message msg = Message.obtain(hRefresh, 1, > i1, i2); > hRefresh.sendMessage(msg); > > return 0; > } // end function > } // end new > ); // end put > > Where IntIntFunction is: > > interface IntIntFunction { > int function(int i1, int i2); > } > > The socket thread works correctly, but after 1/2 minutes the main activity > dies, > with the followin logging: > > I/ActivityManager( 555): Process my.test.testxml1 (pid 650) has died. > D/Zygote ( 529): Process 650 terminated by signal (11) > I/WindowManager( 555): WIN DEATH: Window{522dbc30 > my.test.testxml1/my.test.testxml1.Testxml1 paused=false} > W/UsageStats( 555): Unexpected resume of com.android.launcher while already > resumed in my.test.testxml1 > I/asset ( 555): Creating Asset 0x10279a90 #5 > W/InputManagerService( 555): Got RemoteException sending setActive(false) > notification to pid 650 uid 10020 > > I suppose I'm doing something wrong in the interazione between the 2 > threads: from the documentation > I read I understood that the correct way is to use Handlers for such a task. > > Am I correct? do you see any error in my implementation? > Is there any other way to implement an activity whose interface is updated > by data coming from a socket? > > thanks > giammy > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en