Android的网络 - 最佳实践网络、Android

2023-09-06 21:57:42 作者:熟到陌路

我发展与大部分都是从网上下载列表和表格的应用程序(我有一个JSON服务器我做的请求)。我使用AsyncTasks检索所有数据。我想知道,如果是对付网络的最佳方法,因为应用程序可以(在某些情况下,由OS杀死)通过接收来电,短信或通过让家里BUTTOM pressed简单地发送到后台。当应用程序进入后台发生AsyncTasks什么?被他们杀死,暂停或东西吗?我不想让我的形式和名单半载。我应该使用服务,而不是AsyncTasks?

I'm developing an application with lists and forms which most of them are loaded from the web (I have a JSON server I make requests). I'm using AsyncTasks to retrieve all the data. I was wondering if it's the best way to deal with networking, since the application can be sent to background (and in some cases, killed by the OS) by receiving a call, SMS or simply by having the home buttom pressed. What happens to AsyncTasks when the application goes background? Are they killed, suspended or something? I don't want to have my forms and lists half-loaded. Should I use services instead of AsyncTasks?

感谢您的帮助。

推荐答案

您的AsyncTask将坚持围绕,虽然这将是很好,如果你能告诉任务,尽快尽早换东西了为您的活动转到后台。

Your AsyncTask will stick around, although it would be nice if you could tell the task to wrap things up ASAP as soon as your activity goes to the background.

您通常,除非你打算什么长期的,即是不断在后台运行一些不需要的服务。

You typically don't need a service unless you're planning something long-term, i.e. something that keeps running in the background.