Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'

Below is the Github repistory link for this project, this is just a sample application which fetchs data from firebase realtime databse.: https://github.com/akzarma/testApp

like image 807
akzarma Avatar asked Jul 28 '18 16:07

akzarma


1 Answers

As mentioned in the comments, the most likely reason has to do with SSL. SSL does not play nice with incorrect dates therefore it can not connect securely to Firebase. One possible way around this is to connect to Firebase via http but 1) It is not secure 2) I am not sure if it is still supported.

like image 73
James Avatar answered Nov 18 '22 12:11

James