Imagine you have an application that has let's say a friend list screen created using a FriendListActivity
. Now to create UI for this activity you read data from the DB and create your UI.
Now imagine that you also have a service that runs in background and syncs this database with a remote database using web services.
Now whenever the service updates the friend list in the DB you want to also update your UI accordingly. So, to achieve this you would register content observer in your FriendListActivity
at the time of Activity
launch for Friends URI
(assuming that know the concept of URI
), so that whenever the friend list in database changes you would also update friends list in your FriendListActivity
. Now if the user moved out of your activity or closes the app then you don't need to update your UI (so you don't need to get event for DB changes), so you would unregister the content observer.
Now the next time user comes to this screen, you would again fetch the latest data and register with the DB for content changes...
So the content observer is normally a relation between an activity and database (or specific URI). SO you would register it when the Activity
gets launched and un-register it when the activity goes out of the view..
Hope this helps...