Android中的后台传感器数据收集器 [英] A background sensor data collector in Android

查看:16
本文介绍了Android中的后台传感器数据收集器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在编写一个收集传感器数据的程序,例如一整天的加速度计值.

I am now programming a program that collects sensor data, e.g. acclerometer values for a whole day.

当前我只是使用一个 Activity 并运行该 Activity 一整天(我关闭屏幕自动黑屏),白天不发任何短信或电话.

Current I just use an Activity and run the activity for a whole day (I turn off screen auto-black), and don't make any shortmessages or phone calls during the day.

我听说我可以使用 Service 在后台制作这种长时间运行的数据收集器.但是在我在 http://code.google.com/p/pedometer/.我发现,当屏幕变黑时,计步器不起作用.(但是,只要电源打开,像 predometer 这样的应用程序在任何情况下都应该可以工作.)

I've heard I can make this kind of long running data collector in background using Service. But after I've checked the pedometer at http://code.google.com/p/pedometer/. I found that, when the screen blacks out, the pedometer does not work. (But An application like predometer should work in any case as long as the power is on.)

虽然我不关心总是感应加速度计的电源问题,我确实想黑屏以节省屏幕电量以记录更多的加速度计数据点.

Although I don't care about the power problem of always sensing acclerometers, I do want to black out the screen to save the power in screen to record more acclerometer data points.

我在考虑两种方法:

1. 但是,正如计步器应用程序所示,使用服务.当屏幕变黑时,服务似乎也停止工作了!也许代码有错误.

1.Using an Service, however, as the pedometer application showed. When the screen blacks out, the service seems stoped working too! Maybe the code has bugs.

2.我的应用程序仍然是一个 Activity.但我将屏幕灯改为 0 或全黑以节省电量.

2.My application is still an Activity. But I change the scrren light into 0 or totally black to save power.

我的问题是:对于1)即使屏幕长时间黑屏,Service是否也可以始终运行;2、如何改变屏幕亮度?

My question is that: for 1) does a Service have the abality to be always running even when the screen blacks out for a long time; For 2, how to change the screen light?

谢谢!

推荐答案

关于 1 - 你需要的是一个远程服务.这是一项与本地"服务(在计步器示例中使用)几乎相似的服务,但即使没有绑定任何活动,它也可以在后台运行.您可以关闭屏幕,甚至活动可能会崩溃(在不好的情况下;))但是如果您使用 startService(...) 而不是 bindService(...) 启动它,该服务会继续运行.

concerning 1 - what you need is a remote service. this is a service nearly similar to a 'local' service (that is used in the pedometer example) but can run even if no activity is bound to it, in the background. you can turn off the screen and even the activity can crash (in a bad case ;) ) but the service keeps running if you started it with startService(...) instead of bindService(...).

尝试通过 这个 看看是否有帮助.

try getting through this and see if that helps.

关于 2 - 你真的应该使用 (1) ;)

concerning 2 - you should really use (1) ;)

这篇关于Android中的后台传感器数据收集器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆