android - 在服务中使用 AsyncTask

标签 android android-asynctask android-service

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

最佳答案

Is that a normal practice of using AsyncTask in Service

没有。 AsyncTask 的意义在于能够在后台工作完成后在主应用程序线程上做一些工作。服务很少(如果有的话)需要在主应用程序线程上工作。

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

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

关于android - 在服务中使用 AsyncTask,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38468380/

相关文章:

android - Android 5/L 上缺少控制媒体错误的权限

android - 解析日期 android 0-24 和 12 :00

android - 启动/绑定(bind)服务生命周期。为什么要重新创建

android - Activity 启动时服务未捕获辅助功能事件

android - 防止ndk-build自动清理模块

android - IntelliJ IDEA 数据库插件中缺少 "Android SQLite"项

android - "No enclosing instance of type"在Android中从另一个类调用方法时出错

android - 行变大后 ListView 不会调整大小从异步任务加载图像

android - 滚动顶部时的 Recycler View 应该加载数据

android - Android Services 与 MVVM 中的 Activity 通信(Model View View Model)