我应该为我的应用程序使用 AsyncTask 还是 IntentService? [英] Should I use AsyncTask or IntentService for my application?

查看:22
本文介绍了我应该为我的应用程序使用 AsyncTask 还是 IntentService?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读有关 Android 的互联网连接,并注意到有不同的方法来处理这个问题,即 AsyncTaskIntentService.但是,我仍然不确定该使用哪一个.我的应用程序基本上是一个带有谷歌地图的位置/路径查找器.我的互联网连接将用于在地图的特定半径内找到最近的路径.因此,每次用户将地图移动或滑动到新位置时,它都会更新最近的路径.它还将添加一条新路径,并允许用户对路径进行评分.

I have been reading around on internet connectivity with Android and noticed there are different ways to handle this i.e. AsyncTask and IntentService. However, I'm still not sure which one to use. My application is basically a location/trails finder with Google Maps. My internet connectivity will be used to find the nearest trails within a certain radius of the map. So, every time a user moves or swipes the map to a new location then it will update with the nearest trails. It will also add a new trail, and allow the user to rate a trail.

AsyncTask 是否足以解决这个问题,还是我应该使用 IntentService?

Will AsyncTask suffice for this or should I use IntentService?

推荐答案

您应该使用 AsyncTask 来处理与活动紧密相关的简短重复性任务,例如您当前正在尝试执行的操作.IntentService 更适合于应该在后台运行的计划任务(重复或不重复),独立于您的活动.

You should use an AsyncTask for short repetitive tasks that are tightly bound to an activity, like what you're currently trying to do. IntentService are more geared towards scheduled tasks (repetitive or not) that should run on the background, independent of your activity.

这篇关于我应该为我的应用程序使用 AsyncTask 还是 IntentService?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆