[英]Android on Kotlin: How to pass data from an Activity to an event listener?
(Android newbie learning Kotlin here...) I have an app with 3 components: A UI activity where a user indicates what color car she wants to see; (Android 新手在这里学习 Kotlin ......)我有一个包含 3 个组件的应用程序:一个 UI 活动,用户指示她想看什么颜色的汽车; A service that uses the device's camera to observe a road and report every car that passes by;使用设备的摄像头观察道路并报告每辆经过的汽车的服务; And an event listener latched on the service.并且事件侦听器锁定了该服务。 The job of the event listener is to determine whether any car reported by the camera is of the requested color and, if so, do something about it.事件侦听器的工作是确定摄像头报告的任何汽车是否具有请求的颜色,如果是,则对其进行处理。
I'm tripping over something that's probably basic: how does the listener know what color to look for?我被一些可能很基本的东西绊倒了:听众怎么知道要寻找什么颜色? I can:我可以:
What's the proper way to do this?这样做的正确方法是什么? Many thanks!非常感谢!
I think you can take help of the Shared preferences to store the value(ie color)or you can do as you mentioned in the 4th point.我认为您可以借助共享首选项来存储值(即颜色),或者您可以按照您在第 4 点中提到的方式进行操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.