Android 网络 - 最佳实践
我正在开发一个带有列表和表单的应用程序,其中大部分是从网络加载的(我有一个我发出请求的 JSON 服务器)。我正在使用 AsyncTasks 来检索所有数据。我想知道这是否是处理网络的最佳方式,因为应用程序可以通过接收电话、短信或简单地按下主页按钮来发送到后台(在某些情况下,被操作系统杀死)。当应用程序进入后台时,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?
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 AsyncTask 将保留下来,尽管如果您可以在 Activity 进入后台后立即告诉任务将事情结束,那就太好了。
您通常不需要服务,除非您正在计划一些长期的事情,即在后台持续运行的事情。
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.