Usman khan

I have an android app that has 3 activities :

  1. A login activity
  2. A tasks acivity where all tasks pertaining to a user are displayed (Populated using an Array Adapter)
  3. A task_details activity which results from clicking a task on the list

I have to consume REST Apis. The research I have done so far directs me to use Retrofit. I checked how to use it and found out that :

  1. Set the base URL in the Main Activity (Mine is the Login Activity)
  2. I need to create a API class and define my functions using annotations.
  3. Use the class Rest Adapter in the Activity and define Callbacks.

Had my app been a single activity app, I would have crunched everything in my but I don't know how and where to put all the code from steps 1,2,3 for use in my 3 activities.Could you please help by telling how to use Retrofit in my app. Thanks a lot.

Specifically, I need network calls to : 1. Login the user 2. Get all the tasks of the user. And for both I would be using a given REST api.

2019-06-29 22:17:12

Your Answer This

petter john

Using Retrofit is quite simple and straightforward.

First of all you need to add retrofit to your project, as example with Gradle build sytem.

compile 'com.squareup.retrofit:retrofit:1.7.1' |

another way you can download .jar and place it to your libs folder.

Then you need to define interfaces that will be used by Retrofit to make API calls to your REST endpoints. For example for users:

Response this asnwer Please login to answer this question or answer by facebook comment..