gpt4 book ai didi

android - 我正在开发 Android Auto Media App,但无法理解 MediaBrowserService 的生命周期

转载 作者:行者123 更新时间:2023-11-29 15:41:07 25 4
gpt4 key购买 nike

在创建 android Auto media App MusicService 类时,会创建扩展 MediaBrowserService 的类,这两个方法会自动实现 onGetRoot 和 onLoadChildren。任何人都可以详细解释每件事是如何工作的。

最佳答案

MediaBrowserService 的生命周期看起来像它扩展的简单 Service 的生命周期。 From documentation:

The lifecycle of the MediaBrowserService is controlled by the way it is created, the number of clients that have are to it, and the calls it receives from media session callbacks. To summarize:

  • The service is created when it is started in response to a media button or when an activity binds to it (after connecting via its MediaBrowser).
  • The media session onPlay() callback should include code that calls startService(). This ensures that the service starts and continues to run, even when all UI MediaBrowser activities that are bound to it unbind.
  • The onStop() callback should call stopSelf(). If the service was started, this stops it. In addition, the service is destroyed if there are no activities bound to it. Otherwise, the service remains bound until all its activities unbind. (If a subsequent startService() call is received before the service is destroyed, the pending stop is cancelled.)

The following flowchart demonstrates how the lifecycle of a service is managed. The variable counter tracks the number of bound clients: life cycle

onGetRootonLoadChildren 用于 manage client connections .

但是要使用 MediaBrowserService 这还不够,所以您应该阅读 this documentation (跟随嵌套链接)。

关于android - 我正在开发 Android Auto Media App,但无法理解 MediaBrowserService 的生命周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40235371/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com