Populating Spinner With Json In Android 4.2 Using Asynctask
Solution 1:
The point behind AsyncTask
is to allow you to run background work on a separate thread such as networking stuff so you don't hold up the UI
and users can still do things while data is being downloaded.
Which of my code in the ASyncTask is the parameter that is being passed?
You currently are not passing any params
to the AsyncTask
new MyAsyncTask().execute(); // you would put params in here if needed such as a URL, String, etc...
What is the progress value in my AsyncTask?
As far as I can tell, you don't have one. If you wanted to you could use publishProgress(value)
and that would be sent to onProgressUpdate()
to update things like files downloaded, time of progression, time left, etc...
Finally, is my return value the ArrayList of ManifestItems?
you are returning jobList
so that is what will get sent to onPostExecute()
to do what you need with it
Note: One of the most important things to understand about AsyncTask
is that you can't update the UI
from doInBackground()
so you must do this in one of the other AsyncTask
methods or pass values back to a UI
function. Also, AsyncTask
works differently in 2.3 than it does in 3.0 and beyond. They don't run in parallel any more but put into a queue. So you may want to read about executeOnExecutor() if you want them to run in parallel in 4.2. I hope this answers your questions
executeOnExecutor()(http://developer.android.com/reference/android/os/AsyncTask.html#executeOnExecutor(java.util.concurrent.Executor, Params...)
A couple other things I see is that you will want to add the @Override
annotation to the implemented methods as well as super
calls.
Post a Comment for "Populating Spinner With Json In Android 4.2 Using Asynctask"