1

I want to get the data from onCompleted method and send to my view, but I cant access the results inside the onCompleted method.

public double walletApiCall(final Activity myactivity, final String addresses) {
    double unCon_balance;
    Ion.with(myactivity)
           .load(URL)
            .asString()
            .setCallback(new FutureCallback<String>() {
                @Override
                public void onCompleted(Exception e, String result) {
                    JSONObject tomJsonObject = null;
                    try {
                        tomJsonObject = new JSONObject(result);
                    } catch (JSONException e1) {
                        e1.printStackTrace();
                    }

                    walletApiCall(result,myactivity);
                    System.out.println("unCon_balance2: "+ unCon_balance);
                }
            });

    return unCon_balance;
}
hellow
  • 12,430
  • 7
  • 56
  • 79
zaheer
  • 143
  • 10
  • unCon_balance returns null outside the scope while inside onCompleted method body it prints the value. – zaheer Aug 08 '18 at 08:33
  • No, it doesn't. A `double` cannot be `null`. And since you never assign a value to `unCon_balance` it will never yield a correct value and should not even compile. – JimmyB Aug 08 '18 at 08:48
  • Notice that the callback is *not* called before `walletApiCall` returns; it is an asynchronous callback which will be called some time in the future when the request completes. You cannot return its result before it was even executed. – JimmyB Aug 08 '18 at 08:51
  • thank you for your kind reply JimmyB. Is there,s any way to get that result after the process finished? it actually not returning null it returning 0.0, – zaheer Aug 08 '18 at 08:53
  • Yes. The result is available inside the callback code. From there you can pass it as a parameter to any method you like. – JimmyB Aug 08 '18 at 08:55

0 Answers0