Android的 - 在后台运行 - 服务与标准的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
创建服务做的工作,并具有活动启动服务 VS. 创建一个标准的Java类做的工作,并具有活动创建一个类的对象,并调用方法,做的工作在不同的线程。
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的 - 在后台运行 - 服务与标准的java类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!