background preloader

Observer

Facebook Twitter

Java Code Example for android.database.ContentObserver. The following code examples are extracted from open source projects. You can click to vote up the examples you like. The votes will be used to predict good API usage examples and more good examples will be extracted based on the votes. Code Example 1: From project TextSecure, under directory /src/org/thoughtcrime/securesms/. Source ConversationListActivity.java private void initializeContactUpdatesReceiver() { ContentObserver observer = new ContentObserver(null) { @Override public void onChange(boolean selfChange) { super.onChange(selfChange); RecipientFactory.clearCache(); } }; getContentResolver().registerContentObserver(ContactAccessor.getInstance().getContactsUri(), true, observer);} Code Example 2: From project AnySoftKeyboard, under directory /src/com/anysoftkeyboard/dictionaries/. Source ContactsDictionary.java Code Example 3: Source AndroidUserDictionary.java Code Example 4: From project platform_packages_apps_email, under directory /src/com/android/email/activity/.

Code Example 5: Object Observer pattern in Android ? | Android World. Android Observers and Observables - How to Update Activities Automatically Upon Data Changes! Extending the Android Observer and Observable Classes for Auto Updates The beauty of using an object oriented language such as Java is the ability to extend other classes on your object. Two awesome example of this are the Java Observer and Observable classes. By extending the Observable class on your data object (model), you are able to assign Observers which listen for changes in said data model.

When the data changes, the Observer is notified automatically and fires its update() method. Refresh your Views in the update() Method The update() method is an obvious place to put your code which refreshes the views impacted by the changes in data, this is where the linkage between the views and the data model occurs (usually in the Android Activity). The beauty of using the Observer and Observable classes is that the data model, views and controller (the Activity that updates the views) are all separated. How this Example Works The main Activity ObserverExample.java The data model Score.java.