Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
建立 CarAppService 和工作階段
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
應用程式必須擴充 CarAppService 類別,並實作其 onCreateSession 方法,該方法會傳回對應於目前主機連線的 Session 執行個體:
class HelloWorldService : CarAppService() {
override fun onCreateSession(sessionInfo: SessionInfo): Session {
return HelloWorldSession()
}
// ...
}
應用程式首次啟動時,Session 執行個體會傳回要使用的 Screen 執行個體:
class HelloWorldSession : Session() {
override fun onCreateScreen(intent: Intent): Screen {
return HelloWorldScreen(carContext)
}
}
如果車輛應用程式必須從「首頁」或「登陸」畫面以外的畫面啟動 (例如處理深層連結時),您可以使用 ScreenManager.push,從 onCreateScreen 返回時預先填入畫面返回堆疊。預先填入可讓使用者從應用程式顯示的第一個畫面返回先前的畫面。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2026-06-29 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2026-06-29 (世界標準時間)。"],[],[]]