3

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
    }
pawchi
  • 77
  • 7

1 Answers1

4

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

Vishnu
  • 663
  • 3
  • 7
  • 24