メディア ブラウザ サービスのライフサイクル
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
このセクションでは、一般的なユーザー ワークフローで Android Automotive OS(AAOS)と Android Auto がメディア ブラウザ サービスと対話する仕組みについて説明します。
ユーザーが AAOS または Android Auto でアプリを起動します。
ホストアプリはメディア ブラウザ サービスにバインドします。このサービスは、まだ実行されていない場合は OS によって起動されます。onCreate()
メソッドの実装では、MediaSessionCompat
オブジェクトとそのコールバック オブジェクトを作成して登録する必要があります。詳しくは、メディア セッションを登録するをご覧ください。
AAOS または Android Auto は、サービスの onGetRoot
メソッドを呼び出して、コンテンツ階層のルートを取得します。ルートは表示されません。代わりに、以降のステップでアプリからより多くのコンテンツを取得します。
AAOS または Android Auto は、サービスの onLoadChildren()
メソッドを呼び出して、ルートのメディア アイテムの子孫を取得します。AAOS と Android Auto は、これらのメディア アイテムを最上位のコンテンツ アイテムとして表示します。システムが表示するコンテンツについて詳しくは、ルートメニューを構造化するをご覧ください。
ユーザーがブラウズ可能なメディア アイテムを選択すると、サービスの onLoadChildren()
メソッドが再度呼び出されます。
ユーザーが再生可能なメディア アイテムを選択すると、AAOS または Android Auto は、適切なメディア セッション コールバック メソッドを呼び出して、操作を実行します。
アプリでサポートされていれば、ユーザーはコンテンツを検索することもできます。この場合、AAOS または Android Auto は、サービスの onSearch()
メソッドを呼び出します。詳しくは、ブラウズ可能な検索結果を表示するをご覧ください。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-08-22 UTC。
[null,null,["最終更新日 2025-08-22 UTC。"],[],[],null,["# Media browser service lifecycle\n\nThis section describes how Android Automotive OS (AAOS) and Android Auto\ninteract with your media browser service during a typical user workflow:\n\n1. The user launches your app on AAOS or Android Auto.\n\n2. The host app binds to your media browser service, which the OS starts if it\n isn't already running. In your implementation of the `onCreate()` method,\n you must create and register a [`MediaSessionCompat`](/reference/android/support/v4/media/session/MediaSessionCompat) object and its\n callback object. To learn more, see [Register a media session](/training/cars/media/enable-playback#registering_mediasession).\n\n3. AAOS or Android Auto calls your service's [`onGetRoot`](/training/cars/media/content-hierarchy#onGetRoot) method to\n retrieve the root in your content hierarchy. The root is not displayed.\n Instead, it retrieves more content from your app in subsequent steps.\n\n4. AAOS or Android Auto calls your service's [`onLoadChildren()`](/reference/androidx/media/MediaBrowserServiceCompat#onLoadChildren(java.lang.String,androidx.media.MediaBrowserServiceCompat.Result%3Cjava.util.List%3Candroid.support.v4.media.MediaBrowserCompat.MediaItem%3E%3E)%5D) method to\n retrieve the descendants of the root media item. AAOS and Android Auto\n display these media items as the top level of content items. See\n [Structure the root menu](/training/cars/media/content-media-browser/content-hierarchy#root-menu-structure) to learn more about what the system expects.\n\n5. When the user selects a **browsable** media item, your service's\n `onLoadChildren()` method is called again.\n\n6. If the user selects a **playable** media item, AAOS or Android Auto calls\n the appropriate media session callback method to perform the action.\n\n7. If supported by your app, the user can also search your content. In this\n case, AAOS or Android Auto call your service's [`onSearch()`](/reference/androidx/media/MediaBrowserServiceCompat#onSearch(java.lang.String,android.os.Bundle,androidx.media.MediaBrowserServiceCompat.Result%3Cjava.util.List%3Candroid.support.v4.media.MediaBrowserCompat.MediaItem%3E%3E)) method.\n To learn more, see [Display browsable search results](/training/cars/media/create-media-browser/browsable-search)."]]