为什么要使用机器人服务? [英] Why use a android service?

查看:134
本文介绍了为什么要使用机器人服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道什么是使用的Andr​​oid服务做后台工作的时候,你需要做很多事情只是访问任何公共方法或从一个业务数据的一大块,如较大的List对象的点。

Im wondering what is the point of using a android service to do background work when you need to do a lot of things just to access any public methods or get a large chunk of data from a service such as a larger List object.

为什么不直接使用一个简单的POJO,做的东西在后台为你在一个单独的线程,如果你喜欢,并获取其公共方法不会造成使用AIDL接口,绑定到服务等等等等?

why not just use a simple POJO that does stuff in the background for you in a seperate thread if you like and gain access to its public methods without creating interfaces using AIDL, binding to a service etc etc?

似乎洙许多工作需要做,从服务类访问方法或者是在Android的服务类真的不点?

seems soo much work needs to be done to access a method from a service class or is that really not the point of a service class in android?

我已经开发了从Web服务得到100的项目在XML结构的机器人服务类是谁,然后解析成一个POJO,然后将其存储在一个列表,但我很难找到一个方法来发送名单回调用该服务的活动。

i have developed a android service class that gets 100's of items in a xml structure from a web service who i then parse it into a POJO that is then stored in a List but i am having difficulty finding a way to send this List back to the activity that called this service.

我读过有关使用parcebales对象,但是,随着所有的intent.putExtra有一个大小的限制,所以我可能会遇到在未来的问题。

i've read about using parcebales objects but that along with all the intent.putExtra have a size limitations so i may run into problems in the future.

我想到开沟的Andr​​oid服务的和我很快发现,就是我不喜欢使用它们摆在首位:(

i am thinking of ditching Android services and i have quickly found out why i dont like using them in the first place :(

一个简单的 SomeBackgroundPojo backroundTask =新SomeBackgroundPojo(); backgroundTask.getData();

看起来SOOOO不是处理parcelables的,serealizable对象,AIDL,结合欧洲房车锦标赛等一切只是为了实现刚才输入上面的两行codeI容易得多:(

Seems soooo much easier than dealing with parcelables, serealizable objects, AIDL, binding etcc etc all just to achieve the two lines of code i just typed above :(

推荐答案

鸡蛋里挑骨头:运行一个线程后台任务的对象不 precisely 什么是通常由一个的plain Java对象

Nitpick: an object running a threaded background task ain't precisely what's usually meant by a plain old Java object.

如果你不小心发生了哪些工作正在做,如果其要求的活动或应用程序关闭,然后通过各种手段规避服务。一个服务的要点是,他们可以在用户离开一个活动活路:如果你只是在做的工作,以填补一个UI 的ListView ,所有指使用如一个的AsyncTask ,如在<一个讨论href="http://stackoverflow.com/questions/3067324/android-run-in-background-service-vs-standard-java-class">this早期的问题。

If you don't care what happens to the work being done if its requesting Activity or Application is shut down, then by all means avoid services. One of the main points of Services is that they can stay alive when the user navigates away from an Activity: if you're only doing work to fill a UI ListView, by all means use e.g. an AsyncTask, as is discussed in this earlier question.

这篇关于为什么要使用机器人服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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