Oscar Jarabo
Jul 25, 2017 · 1 min read

Great Post Zhuinden, thanks for sharing. I can see some of my mistakes on your comments.

I have a question when using retrolambda. Untill now, I was using Realm mDB = Realm.getDefaultInstance() inside onCreate and I used to close it inside onDestroy of the Activity.

However, some of my queries are used by many activities. So, I created an abstract class with common functions querying to Realm. For example:

public static User getUser(){

try(Realm r = Realm.getDefaultInstance()){

return r.where(User.class).equalTo(“uID”, SyncUser.currentUser().getIdentity()).findFirst();

}

}

If I continue opening mDB inside onCreate() this would work, otherwise, it would crash because the realm file is closed.

Do you have any best practices on this?

    Oscar Jarabo

    Written by