Wednesday, February 12, 2014

android-threaded network-related problems


            
An android, the use of socket connected to a server. Now I'm in a cycle of activity required to send data to the server and get the results returned by the server, the current practice is to create a Thread in onCreate, a new thread is a while loop, the loop will sleep every second. There is also a button, click gave the server sends a set of data. My problem is that when the program is running, just click button, all the threads died, including the main thread.
The main thread is very simple, new myThread (); myThread.start (); then is to give the button to set the listener. myThread in roughly as follows:
 
while (1)
{
send ();
reve ();
sendMsgToMainThread () ;/ / change the UI, the content of
TextViewsleep (1000);
}

button in is a send ();
Reply:
In the specific point you can, this is not very detailed
Reply:
The reply was deleted administrator at 2013-11-26 11:15:46

Reply:
You click the button event code is how to write a response?
There may be a network congestion.
You started a thread in onCreate inside, and then send the data sleep 1 millisecond time.
First, make sure that send () This code does execute successfully, and then to receive the data server.

The best of the event code button stickers.
Reply:
Code is too little, do not update the UI thread handling, to update via handler.

No comments:

Post a Comment