将 Android 传感器数据写入 XML 文件
你好 我正在开发一个应用程序,当您按下某个键时,它会从传感器读取数据并将这些数据写入 XML 文件。 我有2个活动,一个用于按钮,另一个是实现sensorEventListener的活动。 问题是我的主要活动是按钮,无法从事件侦听器活动获取数据。 我认为侦听器活动不活动,但是当我创建一个意图并以该意图启动活动时,程序停止工作。该按钮只能创建 XML 文件。 那么我如何从传感器读取传感器数据,以及如何在单击按钮时将它们发送到 XML 文件?
谢谢
hi
i am developing an application that read data from sensors and write those data to an XML file when you press a key.
i have 2 activity one for button and another is an Activity who implements sensorEventListener.
the problem is my main activity is button and couldn't get data from event listener activity.
i think the listener activity is not active but when i create an intent and start activity with that intent the program stop working. the button is able to create XML file solely.
so how could i read sensor data from sensors,and how to send them to XML file when the button got clicks ?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的描述,我认为最好有一个活动(带有启动按钮),并让该活动始终监听传感器值,同时将最新条目存储在内存中。
在您的
onResume
方法中,您可能想要注册侦听器(this)。离开/暂停活动后,不要忘记取消注册
。按下按钮后,将缓存的传感器值写入 XML 文件。
From what u described I think it might be best to have a single activity (with the button to start) and have this activity listening to the sensor values all the time while storing the latest entry in memory.
In the
onResume
method of your you might want to register the listener (this). Don't forget tounRegister
, once you leave/pause the activity.Once you press the button, write out the cached sensor values into your XML file.