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

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

问题描述

在Android中,如果我想做一些后台工作,有什么区别

In Android, if I want to do some background work, what is the difference between

创建一个服务来完成工作,并让活动启动服务对比.创建一个标准的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.

推荐答案

自己做线程是多余的,有解决方案,所以你不必担心并发的困难部分.看看 AsyncTaskIntentService.如果您选择服务,请记住您的服务可能随时被终止.

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

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