Date 4/jul
Asynctask - Android AsyncTask is an abstract class provided by Android which gives us the liberty to perform heavy tasks in the background and keep the UI thread light thus making the application more responsive.
------------------------------------------------------------------------------------------------------------
The basic methods used in an android AsyncTask class are defined below :
doInBackground() : This method contains the code which needs to be executed in background. In this method we can send results multiple times to the UI thread by publishProgress() method. To notify that the background processing has been completed we just need to use the return statements
onPreExecute() : This method contains the code which is executed before the background processing starts
onPostExecute() : This method is called after doInBackground method completes processing. Result from doInBackground is passed to this method
onProgressUpdate() : This method receives progress updates from doInBackground method, which is published via publishProgress method, and this method can use this progress update to update the UI thread
------------------------------------------------------------------------------------------------------------
The three generic types used in an android AsyncTask class are given below :
Params : The type of the parameters sent to the task upon execution
Progress : The type of the progress units published during the background computation
Result : The type of the result of the background computation
--------------------------------------------------------------------------------------------------------
MyTask myTask = new MyTask();
myTask.execute();
In the above snippet we’ve used a sample classname that extends AsyncTask and execute method is used to start the background thread.
Note:
The AsyncTask instance must be created and invoked in the UI thread.
The methods overridden in the AsyncTask class should never be called. They’re called automatically
AsyncTask can be called only once. Executing it again will throw an exception
--------------------------------------------------------------------------------------------------------
For application to have the internet access permission go to the android manifest file and just after the <manifest> and before the <application>
write
< uses-permission android:name = "android.permission.INTERNET" />
-----------------------------------------------------------------------------------------------------------
URL
URL is the acronym for Uniform Resource Locator. It is a reference (an address) to a resource on the Internet.
note -
The term URL can be ambiguous. It can refer to an Internet address or a URL
object in a Java program. Where the meaning of URL needs to be specific, this text uses "URL address" to mean an Internet address and "URL
object" to refer to an instance of the URL
class in a program.
Comments
Post a Comment