Faraday
Faraday

Reputation: 387

How to detect the state of a ProgressDialog

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

Answers (2)

Lucas Ferraz
Lucas Ferraz

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();

Refer to : http://developer.android.com/intl/pt-br/training/monitoring-device-state/connectivity-monitoring.html

http://viralpatel.net/blogs/android-internet-connection-status-network-change/

Upvotes: 1

Shadab K
Shadab K

Reputation: 1755

To detect the ProgressDialog

ProgressDialog progressdialog = new ProgressDialog(getActivity());
progressdialog.show();
if(progressdialog.isShowing())
{
progressdialog.dismiss();
}

Upvotes: 0

Related Questions