The request to the server should perform in the Background, so we will write to create a class that extends from AsyncTask to make request to the server. AsyncTask is designed to perform the work in the background. An AsyncTask is determined by 3 arguments: Params, Progress, Result and done in 4 steps onPreExecute, doInBackground, onProgressUpdate, onPostExecute. We will implement a network connectivity test in onPreExecute (), perform the request to the server in doInBackground () and handle the data returned in the onPostExecute (). The full code as follows:
đang được dịch, vui lòng đợi..