My app needs internet connection so it check if user have connection or not. But it check that only when activity starts so how I can detect if user has no connection after activity is started?
HERE IS CODE WHAT I USE TO DETECT CONNECTION WHEN ACTIVITY STARTS:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main );
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
if (info != null) {
if (!info.isConnected()) {
}
}
else {
Intent intent = new Intent(hello.this, connectionerror.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
hello.this.finish();
}
..... my apps other code continues here........