Here there is the code that check the internet connection and then if the isconnected is false show a message in a allert dialog. The problem is that if isconnected is true and (i tried to put if(isconnected) clause instead if(!isconnected)) every works. But if i put off every network on my phone when VM execute show() every freeze. Why? Thanks to all:
final AlertDialog.Builder dialog= new AlertDialog.Builder(this);
((Button)findViewById(R.id.listabutton)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AsyncTask asyncTask= new AsyncTask() {
boolean isconnected=true;
@Override
protected Object doInBackground(Object[] params) {
ConnectivityManager conMgr = (ConnectivityManager)getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo();
isconnected = activeNetwork != null &&
activeNetwork.isConnectedOrConnecting();
Log.i("StateNet",isconnected+"");
return null;
}
@Override
protected void onPostExecute(Object o) {
if(!isconnected){
dialog.setMessage("Controlla la tua conessione a internet")
.setTitle("Ops problemino con internet")
.setPositiveButton("Ok", ok)
.show();
}
super.onPostExecute(o);
}
};