Reputation: 15432
I would like to use Firebase Remote Config in a background service (that I used to display notifications). Is it possible to do this ?
To be more accurate, is it possible to fetch the remote values in a background service ?
// Code below in a background service ?
mFirebaseRemoteConfig.fetch(cacheExpiration).addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
// get remote values here
}
}
Thanks !!!
Upvotes: 2
Views: 2375
Reputation: 15432
Answer to my own question ! YES, it is possible, simply remove the 'this' in the addOnCompleteListener. It gives :
mFirebaseRemoteConfig.fetch(cacheExpiration).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
// get remote values here
}
}
Seems to work perfectly in a background service.
Upvotes: 5
Reputation: 27221
Have you tried to read manual? https://firebase.google.com/docs/remote-config/android
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Toast.makeText(MainActivity.this, "Fetch Succeeded",
Toast.LENGTH_SHORT).show();
// After config data is successfully fetched, it must be activated before newly fetched
// values are returned.
mFirebaseRemoteConfig.activateFetched();
} else {
Toast.makeText(MainActivity.this, "Fetch Failed",
Toast.LENGTH_SHORT).show();
}
displayWelcomeMessage();
}
Upvotes: -1