在服务中使用AsyncTask [英] Using AsyncTask in Service

查看:77
本文介绍了在服务中使用AsyncTask的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在Service(而非IntentService)中使用AsyncTask的正常做法.还是以其他方式创建后台线程更好?

Is that a normal practice of using AsyncTask in Service (not IntentService). Or is it better to create background thread in another way?

推荐答案

在Service中使用AsyncTask的正常做法是

Is that a normal practice of using AsyncTask in Service

不. AsyncTask的重点是在后台工作完成后能够在主应用程序线程上执行一些工作.服务很少(如果有的话)需要在主应用程序线程上进行工作.

No. The point of AsyncTask is to be able to do some work on the main application thread after the background work is completed. Services rarely, if ever, need to do work on the main application thread.

还是以其他方式创建后台线程更好?

Or is it better to create background thread in another way?

是的:new Thread()将很可能作为AsyncTask的直接替代品.在其他情况下,某种形式的线程池可能有意义.

Yes: new Thread() would be a strong candidate as a straight-up replacement for AsyncTask. In other cases, some form of thread pool might make sense.

这篇关于在服务中使用AsyncTask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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