Android-Droid
Android-Droid

Reputation: 14565

Android threading memory issue

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

Upvotes: 0

Views: 87

Answers (1)

Caner
Caner

Reputation: 59168

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

Upvotes: 4

Related Questions