将 Android 传感器数据写入 XML 文件

发布于 2024-10-01 10:44:37 字数 240 浏览 0 评论 0原文

你好 我正在开发一个应用程序,当您按下某个键时,它会从传感器读取数据并将这些数据写入 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

許願樹丅啲祈禱 2024-10-08 10:44:37

根据您的描述,我认为最好有一个活动(带有启动按钮),并让该活动始终监听传感器值,同时将最新条目存储在内存中。

在您的 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 to unRegister, once you leave/pause the activity.

Once you press the button, write out the cached sensor values into your XML file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文