BozhidarMT
BozhidarMT

Reputation: 83

Android GitHub API multiple HttpConnections same time

I am working on Android application which uses a GitHub API. Now at the current screen which is repository screen I need to get : commits count, releases count, branch count, contributors count, issues and to check that is this repository starred by the authenticated user. I implemented this logic with AsyncTask. I dont like that I use 6 tasks same time with ExecuteOnExecutor. I think that is not good practice but I can not find other way.

  1. Could you please give me some tips for that how can I do that logic in other way?
  2. Also I want to ask you guys which is the best way to make this GitHub API request? I can not make decision what technology to use - AsyncTask or IntentService or something else.

Thank you very much!

Upvotes: 1

Views: 96

Answers (2)

AsyncTask is almost always the wrong choice: complicated error handling, cumbersome API, different implementations on different OS versions, etc.

I would recommend you to take a look at Retrofit library. It has a really nice and easy API to make REST API calls and even parse the responses with GSON if you like. Also, it takes care of the asynchronousity.

If you want to go further, I encourage you to check out rx-java. It might be a complete overkill in your case, and the learning curve is pretty steep, but if you decide to go with it, it opens up an endless possibilities of how to elegantly handle situations such as yours.

Upvotes: 1

dumazy
dumazy

Reputation: 14445

You could implement a SyncAdapter and store the data locally. This way you can let the data sync in the background after a certain period of time (let's say daily). The great advantage of this is that you can check recent data offline even if you havent started your app in the last couple of days. You can also run the SyncAdapter manually to ensure the latest data.

Upvotes: 1

Related Questions