Android Socket Client Didn't Send And Closes Itself
I am pretty new to android and java programming and I need your help. I want to create an Android client and a server on my PC (Windows 7). I checked with putty (a program which im
Solution 1:
Okay my guess is that the problem is that your doing this in the main ui thread which is far from recommended. Instead what you should do is checkout AsyncTask
which is the preferred way of doing this kind of operations (reading from files or web and a bunch of other stuff).
This is easier than it sounds what you need to do is something like this (note this is just to give you a feeling about how it looks):
privateclassCreateSocketTaskextendsAsyncTask<String, Void, String> {
@OverrideprotectedStringdoInBackground(String... urls) {
//Do the socket stuff here...
}
@OverrideprotectedvoidonPostExecute(String result) {
//This is called when doInBackground has finished//From here you'd call a method in the main ui class.
}
}
Heres the android doc
There are a bunch of tutorials on the net so you'll be up and running in no time.
Post a Comment for "Android Socket Client Didn't Send And Closes Itself"