How to handle future in ion library?

71 views Asked by At

I've been working with ion library and I've stored the value returned ( as a string ) in the future variable, but I don't know how to show the results or retrieve it. Here's my code.

 public Future<String> getCars(){

   future =
            Ion.with(this)
           .load("http://localhost:3000/api/cars")
           .asString()
           .setCallback(new FutureCallback<String>() {
               @Override
               public void onCompleted(Exception e, String result) {


               }
           });

   return future;

}

How to handle the variable I'm returning? Is my usage correct in the first place? I would like to know if I'm on the right track, and if I'm, I would like to know how to get json data as a string and show it in a TextView.

Thank you.

1

There are 1 answers

0
koush On

This is correct. Your string is in the "result" variable. Just put it in the TextView using setText.