Search code examples
androiddatecontentobserver

Observe the date in android


Is it possible to observe the date (e.g. like a ContentObserver) so that every time the date changes (either because the time elapsed or the user changed it manually), some code get's executed?

The reason why I need this is the following: I've got a list which is backed by a cursor. The cursor is the result of a SQLite statement containing a predicate date >= strftime('%Y-%m-%d','now'). So if the date changes, some list items have to be removed from the list (which will obviously happen after calling requery() on the cursor).


Solution

  • Just re-query whenever your app is resumed? That would ensure that it's always queried against the current date, because they can't change the date without pausing your app. The other thing to note is that this seems like a real edge case. How often to users change the date (not just the time of day, as you are only comparing m, d, y) manually?