Android的服务多线程设计 [英] Android Service Multiple Thread Design

查看:102
本文介绍了Android的服务多线程设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于机器人和服务的一个新问题。目前,我正在开发,应该将图像发送到一台服务器一个应用程序。它也应当能够发送更多图像平行。

A new question about android and services. Currently I'm developing a App that should send images to a server. It should also be possible to send more images parallel.

我做的,会为每个图像的新形象服务。该活动可以绑定到该服务,并收集有关进展情况的信息。我想告诉每一个图像的当前状态的通知(而当用户点击的通知,与该图像的进展的活动应显示)。

I made a service that creates for every image a new image. The activity can bind to that service and gather information about the progress. I want to show the current status for every image in a notification (and when the user clicks a notification, an activity with the progress for that image should be shown).

但我得到的一些问题的方法。有有绑定错误,通知挂起的事件开始的活动完全地新的,所以我失去了对目前正在发送图像等信息。

But I get several problems with that approach. There are errors with binding, the notification pending event starts the activity completly new, so I lose information about currently sending images and so on.

有人能plase告诉我,我怎么能在一个适当的方式设计出这样的问题。

Can someone plase tell me, how I could design such a problem in a appropriate way.

THX

推荐答案

我会使用在你的应用程序类。 该控制器是相同的所有活动。如果映像加载启动控制器创建新的服务/线程,并监视其状态,并显示该通知。每一个活动现在可以要求控制器其进程的状态,并显示对应的信息给用户。这种方式,控制器生活在应用生命周期将结合到服务,而不是短暂的活性

I would use a Controller object that is created in your application class. This controller is the same for all your activities. If an image upload is started the controller creates a new service/thread and monitors it state and shows the notification. Every activity now can ask the controller for the state of its process and show the corresponded information to the user. This way the controller living in the application lifecyle will bind to the service and not the short lived activity

有马克·布雷迪上droidcon一说起这一点,你可以找到关于 Slideshare的的幻灯片。它在幻灯片中后期变得有趣,当使用的架构标记解释。我打了同样的问题了几个星期,并得出了同样的结果,我很高兴,存在在网络上有关这个主题终于有些类型的资源。

There was a talk from mark brady on droidcon about this you can find the slides on slideshare. It gets interesting in the later part of the slides when the architecture mark used is explained. I fought with the same problem for some weeks and came to the same results and I'm glad that finally some kind of resource exists on the net on this topic.

这篇关于Android的服务多线程设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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