Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
创建 CarAppService 和 Session
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
您的应用必须扩展 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)
}
}
当您的汽车应用必须从不是主屏幕或
着陆屏幕的屏幕启动时(例如处理深层链接时),您可以在从onCreateScreen返回之前使用ScreenManager.push预先植入屏幕的返回堆栈。预先植入可让用户从应用显示的第一个屏幕导航回之前的屏幕。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2026-06-25。
[[["易于理解","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"]],["最后更新时间 (UTC):2026-06-25。"],[],[]]