11

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

Community
  • 1
  • 1
akzarma
  • 179
  • 11
  • Please share the code the you are using to get the data from the database. – Alex Mamo Jul 29 '18 at 10:58
  • @AlexMamo I created whole new application for testing (also shared the code) Same problem is there. – akzarma Jul 29 '18 at 14:36
  • fascinating! is this in debug builds or something, does it make any difference ? – Fattie Jul 30 '18 at 18:05
  • 2
    @Fattie I've tried on both the builds. it behaves exactly same. (also added the link to project in the question) – akzarma Jul 30 '18 at 18:37
  • Not sure how to work around it but one possible reason is `SSLHandshakeException` caused by `CertificateExpiredException`. –  Aug 03 '18 at 19:27
  • just tried on a device 4.4.2. using the project link provided. It synced without any issue ( after changing dates ). Is there specific device that you see this issue on ? – Amod Gokhale Aug 06 '18 at 10:48
  • @AmodGokhale After reading your comment I tried it on 4.4.2 device. if I change the months It is syncing without any issue. but if I change the year to 2019 or more, then it stops syncing. (don't forget to clear the app from memory after changing the dates and then open it) – akzarma Aug 09 '18 at 07:11

1 Answers1

1

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.

James
  • 1,928
  • 3
  • 13
  • 30