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

1
  • 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. Commented Oct 18, 2011 at 8:12

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.