In my android application I am checking whether internet connection is present like this in my main activity. Once internet ( data ) connection failure, then it will show error correctly.
But when I quit the application and turn on internet connection and run app then also it showing the same dialogue ( "no internet connection " ), and it will cleared when I reinstall the app, or restart the device .
My Code
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(R.layout.activity_main);
        setFirsLaunchFlag();
        cd = new ConnectionDetector(getApplicationContext());
        // Check if Internet present
        if (!cd.isConnectingToInternet()) {
            // Internet Connection is not present
            TextView text = (TextView) findViewById(R.id.loads);
            text.setText("Internet connection error.");
            return;
        }
... 
}
I am very new to android.. please help me
Update
boolean connected = false;
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(R.layout.login_layput);
        ConnectivityManager connectivityManager =
                (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
        if(connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED || 
                connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED) {
            //we are connected to a network
            connected = true;
        }
        else
            connected = false;
        if(connected==false){
            TextView text = (TextView) findViewById(R.id.loads);
            text.setText("Internet connection error.");
            return;
        }
... 
}
 
     
     
    