I have use The AsyncTask For connecting Internet. a Progress dialog can show at onPreExecute() and i check is Online of that mobile if yes means it will execute the http connections code also dismiss the progress dialog at onPostExecute() and its work as good.
But i have problem if net connection is available at time of Request and connection closed before get Response means the Progress dialog showing always.
Now i want solve this if interconnect disconnect before get Response mean it's alert me as No internet connection and dismiss the progress dialog (may set loading time limit for 30 seconds).
below is my code.
can any one help?
public class SubjectTask extends AsyncTask<Void, Void, Integer> {
@Override
protected void onPreExecute() {
progressDialog = ProgressDialog.show(Login.this, "Loading",
"Please wait...");
//checkConnection();
}
@Override
protected Integer doInBackground(Void... arg0) {
if (isOnline()) { //using ConnectivityManager And Network Info
try {
//Http Request connections
} catch (Exception e) {
e.printStackTrace();
}
return 1;
} else {
alert("Check your internet connection");
return 0;
}
}
protected void onPostExecute(Integer result) {
super.onPostExecute(result);
if (progressDialog.isShowing()) {
progressDialog.dismiss();
}
}
}