I am developing an application that requires access to a website for data and will show what data is on the device. I want to get data from the Internet in the background and show ProgressDialog or ProgressBar to devices, and when the application receives a response from the server application, open a dialog box or panel and show the data.
For this I use AsyncTask -
The code for AsyncTask is as follows:
ServerTask extends AsyncTask {
@Override
protected void onPreExecute() {
dialogAccessingServer = new ProgressDialog(ctx);
dialogAccessingServer.setMessage(shownOnProgressDialog);
dialogAccessingSpurstone.show();
}
@Override
protected ServerResponse doInBackground(String... urlArray) {
String urlString = urlArray[0];
HttpResponse serverResponseObject = null;
return serverResponseObject;
}
@Override
protected void onPostExecute(HttpResponse serverResponseObject){
dialogAccessingSpurstone.dismiss();
}
}
and calling this code as follows:
ServerTask serverTaskObject = new ServerTask();
serverTaskObject.execute();
HttpResponse response = serverTaskObject.get();
// execute the operation with the response
but ProgressDialog is not displayed. (I think the reason is that this thread is not complete and the android is not valid only when the thread is completed).
-
1- ? , ?
2- ?