Android Retrofit - Callback vs no call back -


i analyzing retrofit on android , had question on callbacks vs not using them. under impression callbacks used success , failure responses client might desire. otherwise omit it. here example of retrofit interface without callback:

 public interface githubservice {   @get("/users/{user}/repos")   list<repo> listrepos(@path("user") string user); } 

and here example callback (i hope have right):

   public interface githubservice {   @get("/users/{user}/repos")   list<repo> listrepos(@path("user") string user,callback<repo> cb); } 

im confused on 2 things:

  1. the return value in interface list me should void because retrofit use gson convert json response repo pojo. have create repo pojo expect last piece of code instead:

    public interface githubservice {

    @get("/users/{user}/repos")

    void listrepos(@path("user") string user,callback cb); }

what purpose of return value?

  1. my second question : callback necessary know if request success or failure see docs callback has 2 methods: failure , success.

i want try , answer question

1. correct, return value should void, response callback

2. yes is, callback needed check whether request successful or not, there grab server response.

hope useful, cheers!


edit : can use direct return value or use callbacks response. quoting retrofit documentation site :

  • a method return type executed synchronously.
  • asynchronous execution requires last parameter of method callback.

so guess documentation answers really, callback needed if want execution asynchronous :d


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -