Tuesday 31 July 2018

Why Firebase stops syncing when local date of device is changed explicitly?

When I change my Phone's Local Date setting by 1 or more months and then after restarting my android app which uses Firebase real time database, it doesn't load the data from database and keeps on loading forever. Why does this happen? Does Firebase checks the local time of device before fetching the data?

This is onCreate() MainActivity of Android App

After changing the date (by 10 or more days) in settings and then closing and reopening the app, the progress bar never gets invisible. Not even the onCancelled function get called.

    final ProgressBar progressBar = findViewById(R.id.progress_bar);
    final TextView textView = findViewById(R.id.textView);
    progressBar.setVisibility(View.VISIBLE);

    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference myRef = database.getReference("message");
    myRef.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            String value = dataSnapshot.getValue(String.class);
            textView.setText(value);
            progressBar.setVisibility(View.INVISIBLE);
        }

        @Override
        public void onCancelled(DatabaseError error) {
            progressBar.setVisibility(View.INVISIBLE);
        }
    });`

App level gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.akzarma.testapplication"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.google.firebase:firebase-database:11.8.0'
    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'
}

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

This is the Github repo link for this project: https://github.com/akzarma/testApp



from Why Firebase stops syncing when local date of device is changed explicitly?

No comments:

Post a Comment