1

I have used Square / Retrofit Restful framework to get data from a Restful service, and it works like a charm, code snippet is like below:

FooService restInterface =  new RestAdapter.Builder().setEndpoint(FooService.URL).build().create(FooService.class);
    restInterface.getAllFoos(new Callback<FooModel>() {
        @Override
        public void success(FooModel model, Response response) {
                //get a list of Foo instances.
            }
            updateUI();
        }

        @Override
        public void failure(RetrofitError error) {
                //log errors.
        }

    });

I understand this is an async call, however can I have a spinning icon on the top while retrofit is busy working on the background? In case the network is not available.

Also is it possible to set a timeout so when the time is up, a prompt of options to continue waiting or abort the mission?

I noticed there was something close on this site: Is it possible to show progress bar when upload image via Retrofit 2 , but still couldn't figure it out how to do it. Besides, my requirement might be simpler.

Community
  • 1
  • 1
J.E.Y
  • 1,055
  • 13
  • 31

1 Answers1

2

Yes, this is perfectly possible.

You can make a call to some sort of startSpinner() function just before or even just after the call to the endpoint. Then, in success() and failure(), you can make a call to some sort of stopSpinner() function.

As for the timeout functionality, you sould set the timeout on the underlying HTTP client rather than on Retrofit. If you do not want to use the default timeout, you can read more about setting a custom one here.

Community
  • 1
  • 1
M.S.
  • 1,051
  • 11
  • 27