Google News
logo
Xamarin - Interview Questions
What is an Asynctask in Xamarin.Android?
A staple in Xamarin practical interview questions and answers, be prepared to answer this one using your hands-on experience as mentioned.

AsyncTask is a facility given by Android for executing operations in a background thread without having to manually handle thread creation or execution

Aynctask has following important callback methods :

OnPreExecute :  OnPreExecute is invoked before the actual Background Task is executed. It is used to initialize the Asynctask or setup the task  For example setting up the progress bar to show while the task is being executed
DoInBackground(Params … params) : This is the main call back function which contains the code to do the background operation which may take a long time. The parameters of Asynctask are passed to this step and doInBackground can utilize them
OnProgressUpdate : On Progress Update is a method which is called repeatedly and can be used to publish the progress that has been made by the background tasks so far
OnPostExecute (Result result). : This is invoked on the UI thread. When the task is completed in DoInBackground the result is returned to this call-back. The user can display the result or store for an app to process.

Asynctasks should always be created and loaded on the GUI thread. They cannot be started more than once.
Advertisement