Can we use multiple webservice call in single intentservice's onHandleIntent()? [closed] - android

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

Related

Rest calls & SQLite.NET in fragment or activity [closed]

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 2 years ago.
Improve this question
I am building an Android app which uses activity and fragments and rest calls and a local database. Does anybody know where REST calls is ideal to be placed. I am more interested for fragments but would also like to know about activities as well. I also have a local SLQLite database and I have a method for getting the data. Because a database operation is long running is that similar to a REST call?
Thank you
You SHOULD NOT place long-running operations or any model logic on classes that can be destroyed by configuration changes (rotations, screen changes, phone states), these classes are designed to render the UI to the user.
You should instead use:
ViewModel (for shorter tasks, will only survive as long as the app does) and use a background thread.
https://developer.android.com/topic/libraries/architecture/viewmodel?gclid=Cj0KCQjw09HzBRDrARIsAG60GP-qiuPnYKryrX2YYZI39988xMfqTx4s6fuk5xfKtvuPZ-XQ98DxpgEaAphmEALw_wcB
Services (Recommended, can survive despite your app not being active), make sure to check out the documentation first and some examples.

Long tasks in Application class [closed]

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.

How Retrofit library working faster than default AsyncTask? [closed]

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.

Sending requests in background android [closed]

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

How can I pass an async task from one activity to another? [closed]

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 8 years ago.
Improve this question
I am working on an android app and I have an async task in one activity and I want to use that async task into another activity. Can I do so?
I think AsyncTask do use for in his class.Beacause This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.
AsyncTask must be subclassed to be used. The subclass will override at least one method (doInBackground(Params...)), and most often will override a second one (onPostExecute(Result).)
http://developer.android.com/reference/android/os/AsyncTask.html
I don't think it is possible at all. The one idea that came to my mind is to use Services and do an AsyncTask in it. The service has to be bound.
Yes you can .create a new asynctask class with your common operation. And you can create callback interface and your activity must implement interface to get appropriate callback of asynctask.
Android, can I put AsyncTask in a separate class and have a callback?

Categories

Resources