Android线程内存问题
我想询问一个我需要在 Android 应用程序中实现线程的基本方案。此时我的方案如下所示:
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.
}
所以基本上我想在线程上运行所有内容,发送参数并接收服务器响应。我需要这个,因为有时当我的响应太大时,我会收到 OutOfMemoryException (或者至少我认为这可以解决问题)。
那么有什么想法我的应用程序必须使用什么样的结构吗?
PS 我的 OutOfMemory 问题(您可以在其中查看有关我的问题的更多信息): Android HttpEntityUtils OutOfMemoryException
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您使用
AsyncTask
来完成此任务。它比使用线程更容易。这是解释&示例:http://developer.android.com/reference/android/os/AsyncTask .html
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