Kingfisher Phuoc
Kingfisher Phuoc

Reputation: 8190

problem at the first launch RemoteConfig with conditions

I am facing an issue with the RemoteConfig param which has conditions. Most of the time, I get the default value at the first app open. After that, I get the other condition values. My conditions are User in random percentile from 0 -> 10, 10 -> 20, 20 -> 30,...., 90 -> 100. As my opinion, it's should never be the default value (because the conditions cover 100% of user percentile). I did call fetchAndActive() and call mFirebaseRemoteConfig.getString() after task.isSuccessful(). Any idea?

Upvotes: 5

Views: 2598

Answers (2)

Kingfisher Phuoc
Kingfisher Phuoc

Reputation: 8190

after a lot of days on searching, but there's no clue about it, I had to do a dirty, tricky method to solve my issue: fetch and load the remote config after 1s on onCreate:

Observable.timer(1, TimeUnit.SECONDS)
                    .observeOn(AndroidSchedulers.mainThread())
                    .doOnNext(time ->{
                        fetchAndActiveRemoteConfig();
                    })
                    .subscribe();

P/s: it works but I dont know why it works.

Upvotes: 1

Pavel Marchenko
Pavel Marchenko

Reputation: 301

I faced the same issue more than a week ago and after some googling the only similar thing I found was this question. Today I finally found the reason and implemented simple workaround. Long story short there is a race condition in Firebase SDK initialization connected to 'FirebaseInstanceId' generation: during initial launch Firebase does remote config request before generating AppInstanceId. Because of this backend is not able to apply some conditions related to remote params, like 'user in random percentile'. To fix this we need to generate app instance id before initializing the SDK. So the code may look like this:

FirebaseInstanceId.getInstance().getInstanceId()
    .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
    @Override
    public void onComplete(@NonNull Task<InstanceIdResult> task) {
        //init firebase remote config here
    }
});

Hope this will help.

Upvotes: 5

Related Questions