Reputation: 387
My Activity checks for internet connectivity and displays a ProgresDialog if there's connectivity. Now, if the ProgressdlDialog is showing and internet connectivity becomes unavailable, the poor ProgressDialog keeps loading till enternity. So, I want detect the state of the progressdialog; and then show an AlertDialog if it's loading and internet connectivity becomes unavailable .
Upvotes: 2
Views: 932
Reputation: 4152
You could use CONNECTIVITY_CHANGE Receiver, to know when connectivity change and than use a method to get the actual state of your connection using below code :
ConnectivityManager cm =
(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null &&
activeNetwork.isConnectedOrConnecting();
http://viralpatel.net/blogs/android-internet-connection-status-network-change/
Upvotes: 1
Reputation: 1755
To detect the ProgressDialog
ProgressDialog progressdialog = new ProgressDialog(getActivity());
progressdialog.show();
if(progressdialog.isShowing())
{
progressdialog.dismiss();
}
Upvotes: 0