Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FirebaseRemoteConfig.fetch() does not trigger OnCompleteListener every time

I'm trying to implement Firebase Remote Config :

override fun onCreate(savedInstanceState: Bundle?) {      val configSettings = FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(BuildConfig.DEBUG).build()      mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance()     mFirebaseRemoteConfig.setConfigSettings(configSettings)     mFirebaseRemoteConfig.setDefaults(R.xml.remote_config_defaults)     fetchRemoteConfig() }  private fun fetchRemoteConfig() {     var cacheExpiration = 3600L     if (mFirebaseRemoteConfig.info.configSettings.isDeveloperModeEnabled) {         cacheExpiration = 0L     }      mFirebaseRemoteConfig.fetch(cacheExpiration)         .addOnCompleteListener { task ->                 if (task.isSuccessful) {                     Log.d(TAG, "Remote config fetch succeeded")                     mFirebaseRemoteConfig.activateFetched()                 } else {                     Log.d(TAG, "Remote config fetch failed - ${task.exception?.message}")                 }                  setupView()             } }  private fun setupView() {     val text = mFirebaseRemoteConfig.getString("my_text")     //... } 

My problem is that the OnCompleteListener is not always called. If I close/open my app several times, the setupView() is not always triggered.

The OnCompleteListener should always be called right? Even if I'm hitting cache?

EDIT: Even if I disable the developper mode the behavior is the same. Sometimes the callback is triggered, sometimes not.

like image 271
guillaume Avatar asked May 28 '16 16:05

guillaume


Video Answer


1 Answers

I was facing the same issue and contacted the firebase support. They replied the following:

There currently is a bug that has been reported where onComplete, onSuccess, and onFailure listeners doesn't get called if fetch() is called too early. [...] Currently there is a work around where you can put the fetch() inside a postResume. You can try using this in the meantime before a solution has been released.

I implemented the workaround accordingly

protected void onPostResume() {     super.onPostResume();      mFirebaseRemoteConfig.fetch(cacheExpiration)             .addOnSuccessListener(new OnSuccessListener<Void>() {                 @Override                 public void onSuccess(Void aVoid) {                     Log.d(TAG, "Fetch Succeeded");                     // Once the config is successfully fetched it must be activated before newly fetched values are returned.                     mFirebaseRemoteConfig.activateFetched();                     // Do whatever should be done on success                 }             })             .addOnFailureListener(new OnFailureListener() {                 @Override                 public void onFailure(@NonNull Exception exception) {                     Log.d(TAG, "Fetch failed");                     // Do whatever should be done on failure                 }             }); } 

So far it seems their proposed workaround has resolved the issue.

UPDATE:

I just got notice from the firebase support. According to them the issue is resolved with the latest Google Play Services update.

A fix to Remote Config not calling listeners after fetching has been released in the newest Google play services update. I'll be closing this case for now. However if you are still experiencing issues, feel free to reach out and let me know.

like image 136
Max Avatar answered Sep 20 '22 16:09

Max