在Android中以固定间隔写入文件
我有一个关于在 Android 中定期写入文件的问题。我想要的是以 500 毫秒的间隔将一些数据记录到位于 /sdcard/ 的文件中。如何使用 TimerTask 类来做到这一点?
I have a question regarding writing into a file at a regular interval in Android. What I want is to log into a file some data into a file which is located in /sdcard/ at an interval of 500ms. How I can do this using the TimerTask class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建一个只要您的应用程序运行就运行的服务。您可以在此处找到有关服务的更多信息:http://developer.android.com/ guide/topics/fundamentals/services.html
确保在应用程序关闭时停止服务。
You could make a Service that runs as long as your application is running. You can find out more about Services here: http://developer.android.com/guide/topics/fundamentals/services.html
Be sure you stop the service when the app shuts down.
您不一定需要使用服务,尽管这肯定是一种选择。
您可以在应用程序启动时启动一个处理程序。
You don't necessarily need to use a Service, although that is certainly an option.
You could just start up a Handler when your app starts.