Android服务在界面之外独立运行。

huangapple go评论66阅读模式
英文:

Android service running independent of UI

问题

我有一个项目,拥有独立的 Android(Java)和 iOS(Swift)客户端。其中一个关键特性是,我们有第三方 API 提供各种事件的监听器(例如第三方聊天服务等)。这些各种第三方 API 都是非阻塞的,采用了监听器模式。

在 iOS 端,我们通常将这些类型的 API 放入非 UIKit 的服务/管理/控制对象中。这样,任何可能需要该功能的视图控制器都可以使用它,我们将供应商特定的 API 从我们的视图控制器和视图模型中抽象出来。

这种将 UI 与服务解耦的方式在我看来很自然,但是我在向我们的 Android 开发人员描述这个概念时遇到了意料之外的困难。我不确定问题是语言障碍,平台术语,还是 Android 使用了不同的模式来解决这个问题。

那么,在 Android 中,用于在应用程序运行时始终保持活动状态的自定义对象,用于监听事件/消息并/或允许活动接收和发送消息,独立于任何特定的活动/片段的正确模式/术语是什么?Android Service 似乎是合乎逻辑的实现,但也许在 Android 中有一些其他常见的模式,用于将某些监听器/发布者 API 与特定活动解耦。我应该如何以能让 Android 开发人员立即理解的术语向他或她描述这个问题?

英文:

I have a project with separate Android (Java) and iOS (Swift) clients. One of the key features is that we have third party APIs that offer listeners for various events (e.g., third party chat service, etc.). These various third-party API are all non-blocking, employing a listener pattern.

On the iOS side, we routinely put these sorts of API into non-UIKit service/manager/controller objects. That way the functionality is available to any view controller that may eventually need it, and we abstract the vendor’s particular API out of our view controllers and view models.

This sort of decoupling of the UI from the service seems natural to me, but I had a surprisingly hard time describing the concept to our Android developers. I’m not sure if the issue was a language barrier, a platform terminology, or whether Android solves this problem using a different pattern.

So, what is the correct Android pattern/terminology for a custom object that is constantly alive while the app runs, listening for events/messages and/or allow allow activities to receive and send messages, independent from any particular activity/fragment? Android Service seems like the logical implementation, but perhaps there is some other pattern common in Android for decoupling some listener/publisher API from particular activity. How can I best describe this to an Android developer in terms that he or she will immediately understand?

答案1

得分: 1

服务,就如你已经指出的。有许多教程可以找到,只需在网络上搜索即可。

英文:

Services, as you already indicated. There are several tutorials available, easily found searching the net.

huangapple
  • 本文由 发表于 2020年9月23日 05:21:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/64017852.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定