0

I would like to ask for a basic scheme that I need to implement for threading in my android application. At this time I have scheme which looks like this :

MyActivity:

public void onCreate(){
  //check some conditions and depending on that starts different methods
}

public void method1(){
 // still checking some shits
}

public byte[] sync(byte[] buffer){
//there is actually thread which synchronize with web server. this method only gets the server responce.
}

public byte[] sendRequest(){
// this method send the params to the server which needed for operations.
}

So basically I want to run everything on a threads, sending the params and receiving the server response. I need this because sometimes when my response is too big I get an OutOfMemoryException (or at least I thinkg that can fix the problem).

So any ideas what kind of structure I have to use about my app?

P.S. My OutOfMemory question (where you can see more about my problem): Android HttpEntityUtils OutOfMemoryException

Community
  • 1
  • 1
Android-Droid
  • 14,365
  • 41
  • 114
  • 185
  • I don't think so, This Thread or AsyncTask is prevent from your OutOfMemory Exception for long data receiving from server, So look at the solution for where you get the OutOfMemory in ByteArray. Or just read the my Answer for your last OutOfMemory question. Thanks. – user370305 Oct 18 '11 at 08:12

1 Answers1

4

I recommend you use AsyncTask for this task. It is easier than using threads. Here is explanation & example:

http://developer.android.com/reference/android/os/AsyncTask.html

Caner
  • 57,267
  • 35
  • 174
  • 180