Introduction
Introduction
Asynctask(Asynchronous
task) in android enable us
to perform the task in Background thread
giving us the way to separate our tedious work from UI Thread and publish our work back to UI thread after our work get completed.
It has following method(listed in sequence of execution):
- onPreExceute
- doInBackGround
- publishProgress
- onProgressUpdate
- onPostExceute
Android Example: Asynctask<Params,Progress,Result>
class AsyncTaskExample extends AsyncTask<Void, Integer, String> { private final String TAG = AsyncTaskExample.class.getName(); protected void onPreExecute(){ Log.d(TAG, "On preExceute..."); } protected String doInBackground(Void...arg0) { Log.d(TAG, "On doInBackground..."); for(int i = 0; i<5; i++){ Integer in = new Integer(i); publishProgress(i); } return "You are at PostExecute";} protected void onProgressUpdate(Integer...a){ Log.d(TAG,"You are in progress update ... " + a[0]); } protected void onPostExecute(String result) { Log.d(TAG,result); } }
Call in your activity(Any):
new AsyncTaskExample().execute() - In Our example
new AsyncTaskExample().executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); - for serial task execute.
new AsyncTaskExample().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)- For Parallel task.
The goal of our Academy writing service is to set the quality standard on the market and to provide customers with an original work of high quality is essay pro legit. Online custom essay writing services provided by our custom writing company are aimed at your academic success.
ReplyDelete