The Problem:
I have a local database (sqlite in this case) with each record representing an object instance of a particular class. For this example lets say I have a class called Product. In this case this is in the Android environment but I'm curious about standard Java as well.
When an application or activity starts I read all the data from DB into volatile memory mostly for display to the user but sometimes the data is modified by the application or changes can be received from "the cloud" in a background process.
Other applications/activities should be notified of any modifications to the database and update themselves and redisplay content as quickly as possible to prevent the user from seeing or modifying outdated Products.
My Proposed Solution:
A basic solution I am thinking of is that the DB is wrapped by a ContentProvider.
Each process has at most one in-memory object per record but there can be many pointers to this object. Calls to the ContentResolver will be wrapped in static methods and there will be a static WeakHashMap that stores all in-memory objects.
The ContentProvider sends a notification when a record is modified and all interested applications are listening using a ContentObserver. The ContentObserver refreshes the in-memory object in the WeakHashMap so that all references get the changes simultaneously.
The final step is to trigger a redisplay by calling an invalidate method on the appropriate Views or something like that. I haven't quite figured this part out yet but it's not as vital.
Your thoughts:
Is my proposed solution any good or am I way off the mark? Whats the best way to solve it in Android such that the user interface isn't out of sync or unresponsive? How would this be solved in desktop Java?
Thanks!