简体   繁体   English

服务还是活动?

[英]Service or Activity?

I'm struggling to decide which class to use, Activity or Service. 我正在努力决定要使用哪个类,活动或服务。 My application is complicated so I will use another example. 我的应用程序很复杂,因此我将使用另一个示例。 A timer. 一个计时器。

I would like to create an application that start to count the seconds when I open the application and keep counting even when I click the back button. 我想创建一个应用程序,当我打开应用程序时,该应用程序开始计时秒数,即使单击后退按钮也保持计数。 When I back to the application it will have a gui that show me the time. 当我返回到应用程序时,它将显示一个GUI,向我显示时间。

So the gui I guess would be the activity and the counting method would be on the service.. but how do I manage that system?how they will be communicating? 因此,我猜gui将是活动,而计数方法将在服务上..但是我如何管理该系统?他们将如何进行通信? how can I do that? 我怎样才能做到这一点?

您可以使用BroadcastReceivers并发送活动将要收听的广播,也可以使用Messenger将消息从服​​务发送到活动

他们可以与意图进行通信,也可以通过共享存储或内容提供商进行通信,...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM