Search code examples
androidfirebaserealm

Android Firebase - Mysterious object keys


I tried pushing an object, extended by RealmObject, to my Firebase Database. And then these key-value pairs appeared out of nowhere: "loaded", "managed", and "valid".

User Object

enter image description here

Pushing User object to Firebase

enter image description here

Sample Firebase Database child

Sample Firebase Database child

build.gradle (Module: app)

apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "sample.project"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    realm {
        syncEnabled = true
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:support-annotations:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.google.firebase:firebase-auth:11.0.4'
    implementation 'com.google.firebase:firebase-database:11.0.4'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    implementation 'com.android.support:cardview-v7:26.1.0'
    implementation 'com.android.support:recyclerview-v7:26.1.0'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'io.reactivex.rxjava2:rxjava:2.1.15'

    implementation 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}

apply plugin: 'com.google.gms.google-services'

My question is, where did those key-value pairs come from?

FYI: I used the following dependecy to fix the issue that I encountered when pushing RealmObjects to Firebase.

 implementation 'io.reactivex.rxjava2:rxjava:2.1.15' 

Referring to this post: Crash combining Firebase and Realm - Failed resolution of: Lio/reactivex/Observable;


Solution

  • My question is, where did those key-value pairs come from?

    From extends RealmObject, of course:

    boolean isLoaded()

    Checks if the query used to find this RealmObject has completed.

    boolean isManaged()

    Checks if this object is managed by Realm.

    boolean isValid()

    Checks if the RealmObject is still valid to use i.e., the RealmObject hasn't been deleted nor has the Realm been closed.

    Realm however provides the way to use @RealmClass public class MyClass implements RealmModel in place of extends RealmObject specifically for cases like this.