Android - 在后台运行 - 服务vs.标准的java类 [英] Android - Run in background - Service vs. standard java class
问题描述
在Android中,如果我想做一些背景工作,
In Android, if I want to do some background work, what is the difference between
创建服务来完成工作,让Activity启动服务
VS.
创建一个标准的java类来完成这个工作,并让Activity创建一个类的对象并调用方法,在单独的线程中进行工作。
Creating a Service to do the work, and having the Activity start the Service VS. Creating a standard java class to do the work, and having the Activity create an object of the class and invoke methods, to do the work in separate thread.
推荐答案
做你自己的线程是过度,有解决方案,所以你不必担心并发的硬性部分。请查看 AsyncTask 或 IntentService 。如果你去服务,请记住,你的服务可以在任何时候被杀。
Doing your own threads is overkill, there are solutions for this, so you don't have to worry about the hard parts of concurrency. Have a look at AsyncTask or IntentService. If you go for a service please keep in mind that your service can be killed at any time.
这篇关于Android - 在后台运行 - 服务vs.标准的java类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!