结算应用程序数据库应用程序、数据库

2023-09-04 23:35:51 作者:侠气

我有一个Android应用程序,它使用SQLite数据库来存储文本数据为特定的用户。读取数据/从/从该周期性每隔n秒后运行的服务的数据库写入。我的要求是根据年龄来清除数据。像,如果该文件是24小时以上的老应予删除。

I have an Android application which uses sqlite database to store textual data for a particular user. The data is read/written from/to the database from a service that runs periodically after every n seconds. My requirement is to clear data depending on age. Like, if the file is more than 24 hours old it should be deleted.

检查文件的年龄似乎很容易,只需比较当前时间与文件的创建时间。现在的问题是:

Checking the age of the file seems easy, just compare current time with the File creation time. The problem is:

我应该把这个检查并删除文件;内部应用程序的onCreate()或用户登录时输入/注销?什么是从触发这一逻辑的理想场所?我应该安排一个报警时,用户登录?

where should I put this check and delete the file; inside application onCreate() or when the user logs in/ logs out? What would be an ideal place to trigger this logic from? Should I schedule an Alarm when the user logs in?

我应该删除的文件或干脆删除行?如果我不触发登录/注销缓存清除逻辑,不会删除该文件造成的问题,特别是如果该服务仍试图读取并从数据库中写?

Should I delete the file or simply delete the rows? If I don't trigger the Cache clearance logic from login/logout, won't deleting the file cause problems, especially if the service is still trying to read and write from the database?

请咨询。

感谢。

推荐答案

那么,这一切都取决于你的逻辑应用程序的第二部分。我看不出你为什么会删除数据库,除非它只是用来存储临时数据并不重要。无论哪种方式的理想场所做这种检查和删除在数据访问类,多数民众赞成打开连接到数据库。下面是我的逻辑...

Well, this all depends on your logic for the application for the second part. I cant see why you would delete a database unless its just used to store temp data that does not matter. Either way the ideal place to do this check and delete is in the Data Access class thats opening the connection to the database. Below would be my logic...

通话打开数据库 检查数据库文件是旧的 如果有,将其删除 开启数据库(应该创建一个,如果它不存在)