Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Today i used retrofit library in my project instead of AsyncTask because it is faster than HttpUrlConnection but i am wondering how it is faster and what mechanism they are using. I searched about that but didn't get the accurate or satisfactory answer. Please help me out to understand the concept behind it.
Async task execute serially and are single threaded by default and they will wait for last call to complete before execution of next one and designed in a way so that to avoid common errors due to parallel running threads. Retrofit is not. It sends calls parallely and use ThreadPoolExecutor.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Is it a good practice to make long tasks such as server requests in the application class? Let's say these requests are for initialization,is it still fine to place these requests in the oncreate method in the Application class.
It is not. Everything inside the onCreate of Application class will be executed in the main thread, resulting in freezing the UI if your task takes a lot of time.
The best practice, when it comes to operations such as communicating witha server, is to implement a Repository Pattern and execute the time consuming operations in a different thread, then use the results in the UI Thread.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am having a hard time in understanding the Retrofit for my App. I want to use retrofit in it but I am not understanding about it much.
Everthing is very confusing in it. Can any one help me to learn it completely
I dont know how to start and from where to start
The links I have gone through while trying to learn are as follows :
Using Retrofit 2.0 in Android
http://www.vogella.com/tutorials/Retrofit/article.html
http://mobilesiri.com/retrofit-tutorial-android-studio/
http://www.androidhive.info/2016/05/android-working-with-retrofit-http-library/
https://futurestud.io/blog/retrofit-getting-started-and-android-client
First you have many different library you can use instead of Retrofit , the basic one and i think the simplest is Okhttp but you have to understand that Okhttp is no more supported but still work when you downgrade your SDKVersion , and you can use Volley to perform the same service as Retrofit
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
As i know intentservice's OnHandleIntent run on separate thread same like asynctask, so can we use two or more webservice call in single IntentService? If we do so.. how android will execute both webservice call? Means is it return result of first webserive call and then execute another?
You can, as much as you could perform many sync http call in a separate thread.
The caveat is that you need to perform synchronous http calls (if you use okhttp or retrofit you need to look for the blocking flavour) and that they will obviously be serialized.
You can do multiple webservices call in single IntentService
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
What is the best way to send requests sequentially in background? I'm having trouble deciding between an AsyncTask, Service or Runnable due to the complexity of my problem. Basically I have a DB, with pending requests, and I want to create a "background job" that doesn't get killed until he finishes his task. This job needs to check if there're any pending request and if yes, send them first. For this I'm planning to have a background task with a queue that consumes the first element and continues the process on success and aborts the operation on failure. It also needs to be a singleton so, if any request arrives while it's still sending pending requests, I can guarantee the sequencial state integrity. Said that what do you guys think is the best android class that will suit my problem? Thanks
I thinking about using this. It looks like a very nice framework to do what I'm looking for https://github.com/path/android-priority-jobqueue
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How does android manages the async tasks as in how are the threads managed in the background and how can i manage threads so that they follow a queue type pattern of execution in android.
AsyncTask uses a ThreadPoolExecutor combined with a LinkedBlockingQueue, so basically it will do what you want, I think. See the source code for more info.