If I want to make a request from an Android device to a remote service, I can use AsyncTask, AsyncTaskLoader, Intent, etc to make the a request apart from the UI thread. It seems there are a lot of options, but I am confused how to choose among them. Could you explain when and which to use? Also, are there any other options besides the ones I have mentioned?
Ways of making async service calls in Android? and when to use which?
261 Views Asked by Grace Huang At
1
There are 1 best solutions below
Related Questions in ANDROID
- Delay in loading Html Page(WebView) from assets folder in real android device
- MPAndroidChart method setWordWrapEnabled() not found
- Designing a 'new post' android activity
- Android :EditText inside ListView always update first item in the listview
- Android: Transferring Data via ContentIntent
- Wrong xml being inflated android
- AsyncTask Class
- Unable to receive extras in Android Intent
- Website zoomed out on Android default browser
- Square FloatingActionButton with Android Design Library
- Google Maps API Re-size
- Push toolbar content below statusbar
- Android FragmentPagerAdapter Circular listview
- Layout not shifting up when keyboard is open
- auDIO_OUTPUT_FLAG_FAST denied by client can't connect to localhost
Related Questions in ANDROID-INTENT
- Unable to receive extras in Android Intent
- Android - No view found for fragment
- I want to Show Simple Toast Message When User Click On Media Controller button Pause/Start/Stop in video View Using Media Controller
- Android Studio - Illegal character 8204 error
- invoking application activity from url in email
- How to send object using getserializable extra method
- Google Play services LocationSettingsAPI - LocationSettingsRequest Dialog not Showing
- How to getCropAndSetWallpaperIntent(Uri imageUri) to work?
- Android put and get parcelable array error
- Save image from Camera take picture intent to application private storage
- how to get the URL from mainActivity to the second activity using intents?
- how to launch an image in a activity by clicking a button in a diffrent activity in android studio
- Cannot start activity using explicit intent
- Getting a files extension from Filepicker-Intent
- About getSharedPreferences
Related Questions in ANDROID-ASYNCTASK
- AsyncTask Class
- Fragment AsyncTask not executing after back button pressed
- change selected gridview cell background in android?
- How can I return an ArrayList from my AsyncTask?
- unfortunately app closed error in android app when i debug the code
- Will fragments in a ViewPager sometimes get garbage collected? An AsyncTask / ListView / ViewPager issue
- Another function is not calling after AsyncTask onPostExecute
- Android Database in AsyncTask in Fragment
- How to play pre-recorded audio in reverse direction, using AudioTrak / AudioRekord IPA and Multithreading
- FATAL EXCEPTION: AsyncTask #1 An error occured while executing doInBackground
- FATAL EXCEPTION: AsyncTask caused by ConcurrentModificationException
- How to restart AsyncTask when wifi change?
- One AsyncTask for multiple Fragments
- Using AsyncTask to login user
- Get value from data base using AsyncTask and change TextView value in Fragment
Related Questions in ASYNCTASKLOADER
- Asynctaskloader restart loading when the activity restart
- Passing data to AsynTask
- Integrating Loaders and recycler view not working
- Android. Yor own progress-bar?
- Xamarin android AsyncTaskLoad class
- Very Basic LoaderTestCase stuck in getLoaderResultSynchronously
- LoaderManager: how to get the right loader from with multiple different loaders?
- AsyncTaskLoader restarts when the activity is recreated
- Ways of making async service calls in Android? and when to use which?
- How to pass params to Android AsnycTaskLoader
- Must an activity or fragment have a separate loader for type of each database operation performed?
- Is it possible to find out if the LoaderManager has finished loading all AsyncTaskLoaders?
- Update progressbar from AsyncTaskLoader?
- Error while using AsyncTaskLoader
- Repeating Listview results with ListFragment Loader AsyncTaskLoader JSON
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
This is an extensively discussed question, since Android provides a long list of mechanisms capable to handle service calls asynchronously, besides the one you mentioned there's also:
Now, the key point in your question is "When to use it" and here would be my answer: In software the only golden rigid rule is the "It depends rule", there's no hard rules for anything in software development there's always different ways to approach a problem in software (i guess that's the reason of the word "soft" in it...) and that's exactly why it always depends, it depends on whatever you need and although one approach might be the most common way to do it like for example "AsyncTask" it doesn't mean at all that AsyncTaks is always the way to go, it always depends on the factors and needs that affect your functionality. There's plenty of things that nowdays get executed using AsyncTaks when maybe all you need could be just a regular common Native Thread.
The only way to be able to make a decision towards the most appropiate approach would be knowing ALL the features around a tool, like for example most people 90% of the time use AsyncTaks just to run doInbackGround on separate thread, but might not even need preExecute, publishProgress, postExecute, etc, and that's something a Regular Thread could do, just like this example there's features for every single object provided in order to do remote calls, however as i already mentioned several times, it all depends on what you need and what tool fits better your needs. Remember there's no hard coded rules for "How, When, and What" to use in software, IT ALL DEPENDS, and making good decisions in that "DEPENDS" makes the difference between good developers from excellent developers...
This is a list of things i usually take on count to implement either one way or another, this list do not apply for all the scenarios but might give you an idea.
AsyncTaks- I know is a good idea to make use of asynctaks when the functionality needs to be monitored, by monitored i mean, i need to keep track of progress during my job, like (download/task progress), because that's exactly what the AsyncTask was originally created for, it was created attached to "The Task Pattern", and if i don't need to make use of at least two methods for monitoring provided by AsyncTaks like onPreExecute,onProgressUpdate, onCancelled etc. I know there might be another way to implement it.
Native Java Threads - I know is good to make use of this tool when my task is not related to any view in android at all, and do not need to be monitored (example: removing/adding data from remote database, and the response might affect just persistence elements that will not be displayed like configuration preferences)
IntentService - When i want to do a one time task in a queueprocessor fashion way, but unliked a native thread, here i would like to have some application context in order to maybe bind an activity etc...
Regards!