How to purge old items from the database and avoid their addition there next time on android?
I have ListView
, which displays records (movies) from the SQLite DB.
Each record there besides other fields has movieId
(unique) and date_added
fields.
My synchronization job gets new movies from the site and add them to DB. At the same time it is supposed to delete movies which were added more than 3 days ago.
But if I just delete them from the DB, then they can be added again during synchronization (since movie with such movieId
will not exist in the DB).
What is the best approach to avoid that? Will it be OK if I wouldn't delete the whole record, but will just zero our all fields except that movieId
? Or, is there another, more correct approach?
If you don't want to display movies that were added more than 3 days ago you'll probably have to keep them in the database.
If you are saving lots of information about each movie, and especially if you are storing images or other data then you may want to zero out the records to save room, otherwise I don't see it being a huge deal. I suppose I don't know the exact effect you are going for but I like keeping data around.
Your only change is instead of using the synchronization job to delete old entries you'll have to use the list adapter to only fetch newer ones in its query.
Leaving only movieId will works till reinstallation. I'd prefer to store such data like who what downloaded on server and filter it during synchronization.
精彩评论