I have this code for a webview so that it shows when there's no connection in Android Studio it shows a message where there's no connection, then the user press a button to see if there's connection again, and it does it well but just the first time it opens. After the page loads with internet and you are navigating on if you deactivate the internet and enter any url it shows the 404 error again instead of showing the layout and the button to retry to connect to the internet.
Here is the code inside another fail created called NoConnection.java to have more order in the coding. It will be great if you tell me exactly what to put and where in the code because I'm kind of a newbie in Android Studio.
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class NoConnection extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_no_connection);
}
public void retry(View view){
if(isNetworkAvailable() == true){
Intent Intent = new Intent(NoConnection.this, SplaceScreen.class);
startActivity(Intent);
}else{
Toast.makeText(this, "No internet connection.", Toast.LENGTH_LONG).show();
}
}
public boolean isNetworkAvailable() {
// Get Connectivity Manager class object from Systems Service
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
// Get Network Info from connectivity Manager
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
// if no network is available networkInfo will be null
// otherwise check if we are connected
if (networkInfo != null && networkInfo.isConnected()) {
return true;
}
return false;
}
}
Now, how can I modify it so that it works after the website loaded and you are navigating on it it shows the message?
Thanks in advance,