I try to save result of calling firebase functions from Android app.My function works well, because I see result in log. But I can't save it into variable for further use. Any ideas?
public void getUserRankFromFirebase(){
mFunctions = FirebaseFunctions.getInstance();
Map<String, Object> data = new HashMap<>();
String resultFBFunctions = "";
mFunctions
.getHttpsCallable("getUserOnCall")
.call(data)
.addOnSuccessListener(getActivity(), new OnSuccessListener<HttpsCallableResult>() {
@Override
public void onSuccess(HttpsCallableResult httpsCallableResult) {
resultFBFunctions = httpsCallableResult.getData().toString();
Log.d("result1", httpsCallableResult.getData().toString()); //I see result here
}
});
Log.d("result2", resultFBFunctions); // No result here
}
onSuccess() is asynchronous. So, when are using the value of resultFBFunctions, it may be empty since the data is not retrieved yet...
The data retrieved is ought to be used inside the onSuccess() method itself
To solve your problem, use the data received inside the onSuccess() method itself
Please specify what is resultFBFunctions used for
This question may help you. Feel free to ask for clarifications
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With