Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase onCall functions save the result to a variable in android [duplicate]

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
    }
like image 507
pawchi Avatar asked Dec 19 '25 12:12

pawchi


1 Answers

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

like image 90
Vishnu Avatar answered Dec 22 '25 10:12

Vishnu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!