Android线程内存问题

发布于 2024-12-10 05:32:26 字数 841 浏览 0 评论 0原文

我想询问一个我需要在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱花细雨 2024-12-17 05:32:26

我建议您使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文