I am using the following if else statement:
if (isInternetPresent) {
    try {
        startActivity(i2);
    } catch (Exception e) {
        AlertDialog.Builder builder = new AlertDialog.Builder(Main.this);
        builder.setTitle("Title");
        builder.setMessage("Message");
        AlertDialog alert = builder.create();
        alert.show();
    }
} else {
    Toast.makeText(getApplicationContext(), "Please check your Internet Connection.", Toast.LENGTH_LONG).show();
}
The problem is when there is no internet connection, it shows the toast, but when I connect to the network (keeping my application on), it shows the same toast. Any help is appreciated.
    check = new CheckInterNetConnection(getApplicationContext());
    isInternetPresent = check.isConnectingToInternet();
this two lines are in my onCreate
 
    