Skip to content Skip to sidebar Skip to footer

Retrofit + Otto + Aa, How To Do Simple Get Request?

I am using Android Annotation for boilerplate, and Retrofit for Api calls, While doing post requests through retrofit I discovered a Some problems: When i am calling asynchronous c

Solution 1:

Why this is running before getting all courses??

Because that's how asynchronous code works?

Retrofit is not a blocking call.

If you want to perform an action from onResponse back on the UI thread, you don't even need an EventBus library, just give the callback as the parameter of the method.

public void GetCoursesList(Callback<List<CourseInfo>> callback)  {
    api.getAllCourses(user.getApikey()).enqueue(callback);
} 

The method is now void because, again, Retrofit doesn't block, so you returned an empty list while the server request occurred

@AfterViewsvoidsetInits(){

    cc.GetCoursesList(newCallback<List<CourseInfo>>() {
        // TODO: Implement the interface 
     } );

    Toast.makeText(this,"Why this is running before getting all courses??",Toast.LENGTH_LONG).show();

}

Post a Comment for "Retrofit + Otto + Aa, How To Do Simple Get Request?"