public class AllDataAsyn extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... params) {
// TODO Auto-generated method stub
getData(params[0].toString());
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
if (isNetworkConnected() == true) {
progressDialog.dismiss();
adapter = new NewsScreenAdapter(NewsScreenActivity.this);
list.setAdapter(adapter);
} else if(isNetworkConnected() == false) {
// runDialog(seconds);
AlertDialog connection = new AlertDialog.Builder(
NewsScreenActivity.this)
.setTitle("No Network Found")
.setMessage(
"Internet Connection Reqired To Use this Application")
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
progressDialog.dismiss();
}
}).create();
connection.show();
}
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
progressDialog = new ProgressDialog(NewsScreenActivity.this);
progressDialog.setMessage("Loding ...");
progressDialog.setCancelable(false);
progressDialog.show();
}
public boolean isNetworkConnected() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if (ni == null) {
// There are no active networks.
// Toast.makeText(getBaseContext(),
// " Internet Connection Reqired To Use this Application",
// Toast.LENGTH_SHORT).show();
return false;
} else
// Toast.makeText(getBaseContext(), " Network Found",
// Toast.LENGTH_SHORT).show();
return true;
}
}
こんにちは、サーバーから 30 秒以内に応答がない場合は、アラートを開きたいと思います。asyncTask でそれを行うにはどうすればよいですか。私はすでにインターネット接続を確認しましたが、応答も確認したい..どうすればそれが可能か教えてください..ありがとう..