Realm Blog

Realm Java 0.90 — Better Date and API Cleanup!

We just released a new version of Realm Java to this website and to Bintray. This release adds full support for the Date datatype as well as an API cleanup.

Better Date support

Realm Java has from the beginning supported the standard java.util.Date, with one limitation. We truncated all timestamps to the nearest second.

The reason was that we wanted all of our products to be compatible, even though their date formats differ widely. Starting with Realm Java 0.90 and Realm Objective-C & Swift 0.101, we have fixed these issues and Realm Java now supports the full millisecond precision that is normally offered by the Date class.

This change will require an upgrade of the format of the Realm file, but it will happen automatically when opening a Realm file using 0.90+. Enjoy all those milliseconds :D

Android Adapters

We have decided to split off all Android-specific components into their own repository. This will make it easier to release enhancements and hotfixes for those as well as keeping the general size of the main library down.

This means that from 0.90, the class RealmBaseAdapter is no longer part of the main Realm library, and you will have to add the following dependency to get it:

dependencies {
	compile 'io.realm:android-adapters:1.0.1'

Going forward we are planning to add more Android framework support like RecyclerView and Cursors, but if you have any other ideas or feedback, please create an issue in the new Realm Android Adapters repository.

API Cleanup

Realm Java has been in beta for roughly 1.5 years, and during that time we have gotten a lot of feedback and input on how the API should look. For that reason we are now taking the opportunity to do a general cleanup. We are removing things that are not really used and improving others.

The most important items are below:

  • All Realm classes are now final.

  • RealmChangeListeners now send the changed object as a parameter to onChange().

realm.addChangeListener(new RealmChangeListener<Realm>() {
	public void onChange(Realm realm) {
		// A reference to Realm. Note that all Realm instances and objects
		// are live objects, so this is just convenience and it cannot
		// be compared to previous references as they will all be the same.

Person p = realm.where(Person.class).findFirst();
p.addChangeListener(new RealmChangeListener<Person>() {
	public void onChange(Person person) {
		person.getName(); // The updated person.
  • All query methods on Realm and DynamicRealm have been deprecated. All query methods should be done through Realm.where(), DynamicRealm.where() or RealmCollection.where().

  • RealmConfiguration.Builder.setModules() has been renamed to RealmConfiguration.Builder.modules().

  • Realm.refresh() has been deprecated in favor of Realm.waitForChange(). See this gist for an example of how to use it. This change was motivated by the fact that one-time tasks should either use the asynchronous API’s or open a Realm instance and close it again when done with it. waitForChange() is more suited for use-cases where you can’t use the async API (because it requires a Looper thread).

calling waitForChange() will block the current Thread until a commit happens in the background or you call stopWaitForChange(), which will stop the wait of the Thread that called waitForChange().

See the full changelog for all the details.

Thanks for reading. Now go forth and build amazing apps with Realm! As always, we’re around on Stack Overflow, GitHub, and Twitter.

Realm Team

At Realm, our mission is to help developers build better apps faster. We provide a unique set of tools and platform technologies designed to make it easy for developers to build apps with sophisticated, powerful features — things like realtime collaboration, augmented reality, live data synchronization, offline experiences, messaging, and more.

Everything we build is developed with an eye toward enabling developers for what we believe the mobile internet evolves into — an open network of billions of users and trillions of devices, and realtime interactivity across them all.

Get more development news like this