ANDROID:是否有可能创建一个数据库,并保存了一些信息,它每隔100秒 [英] ANDROID: is it possible to create a database and save some information in it every 100 seconds
问题描述
我收集里面的一个微调的一些信息和这些信息可以更改
I collect some information inside a Spinner and this information can change
例如东西可能会消失或新的东西可能会
for example something may disappear or something new may come
我希望应用程序的存储这些信息在数据库中每隔100秒
是否有可能做这样的事?
is it possible to do something like this?
我想建立一个数据库,并在此数据库中存储这些信息。
I'm thinking of creating a database and within this database storing this information
但我不知道这每隔100秒的一部分,我将如何做到这一点?
but I'm not sure about this "every 100 seconds" part, how would I do this?
我在想,也许我将不得不创建一个过程
将并行运行,这一过程将有一个时间计数器,当100秒钟过去了,将存储在数据库中的信息的功能将被调用
I'm thinking that maybe I will have to create a process
that will be running in parallel, this process will have a time counter and when 100 seconds have passed, the function that will store the information in the database will be called
但我不知道这是可能的。我的意思是,建立这样一个计数器,将并行运行的其它应用。
But I'm not sure if this is possible. I mean, creating such a counter that will run in parallel with the other application.
也许有一些更简单
在此先感谢
推荐答案
转念一想: 这可能不是要走的路(AlarmManager)。更好的方法是将一个监听绑定到微调。这样,你会才反应过来,并保存数据时有新的数据来保存。
On Second Thought: This is probably not the way to go(AlarmManager). A much better way would be to bind a listener to the spinner. That way you will only react and save data when there is new data to save.
您可以提供的微调一些细节你正在使用,也许我们就可以处理事件绑定。
Can you provide some details on the Spinner you are using and perhaps we can work out the event binding.
对于存储,使用SQLite:的http://developer.android.com/reference/android/database/sqlite/package-summary.html
For the storage, use SQlite: http://developer.android.com/reference/android/database/sqlite/package-summary.html
有关100秒的时间间隔,使用AlarmManager:
For the 100 second interval, use the AlarmManager:
这个类提供访问系统报警服务。这允许 您安排您的应用程序将在在一些点运行 未来。当警报响起时,意图已被注册 为它是由系统广播,自动启动所述目标 如果它尚未运行的应用程序。注册警报 保留,而在设备处于睡眠状态(并且可任选地唤醒 设备,如果他们在这段时间去关闭),但如果将被清除 被关闭和重新启动。
This class provides access to the system alarm services. These allow you to schedule your application to be run at some point in the future. When an alarm goes off, the Intent that had been registered for it is broadcast by the system, automatically starting the target application if it is not already running. Registered alarms are retained while the device is asleep (and can optionally wake the device up if they go off during that time), but will be cleared if it is turned off and rebooted.
http://developer.android.com/reference/android/app/ AlarmManager.html
看看这个答案为code样品,并进一步讨论:的Android AlarmManager
Take a look at this answer for a code sample and further discussion: Android AlarmManager
这篇关于ANDROID:是否有可能创建一个数据库,并保存了一些信息,它每隔100秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!