Android app not reconnecting

general-dev
#1

I have developed an android app, but my problem is it not reconnecting back to the internet when its in use. that is when disconnect internet it crushes. I need it to connect back internet when you turn on internet connection while the App in still on

this my code

public class MainActivity extends Activity implements View.OnClickListener {
    Button Register_Now;
    Button Login;
    EditText ET_USER_NAME;
    EditText ET_USER_PASS;
    AlertDialog.Builder builder;
    TextView textView1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ET_USER_NAME = (EditText) findViewById(R.id.user_name);
        ET_USER_PASS = (EditText) findViewById(R.id.user_pass);
        Register_Now = (Button) findViewById(R.id.userReg);
        Login = (Button) findViewById(R.id.login_button);

        Login.setOnClickListener(this);
        Register_Now.setOnClickListener(this);
        textView1 = (TextView) findViewById(R.id.textView1);


        ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        if ((connectivityManager
                .getNetworkInfo(ConnectivityManager.TYPE_MOBILE) != null && connectivityManager
                .getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED)
                || (connectivityManager
                .getNetworkInfo(ConnectivityManager.TYPE_WIFI) != null && connectivityManager
                .getNetworkInfo(ConnectivityManager.TYPE_WIFI)
                .getState() == NetworkInfo.State.CONNECTED)) {
            textView1.setVisibility(View.INVISIBLE);
        } else {
            Register_Now.setEnabled(false);
            Login.setEnabled(false);
        }
    }
0 Likes

closed #2

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.

0 Likes