Android - 在后台运行 - 服务vs.标准的java类 [英] Android - Run in background - Service vs. standard java class

查看:199
本文介绍了Android - 在后台运行 - 服务vs.标准的java类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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屋!

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