title: How to Cache a URL and load while offline?
body: <p>This is my code. As I am new to andorid, I have no idea what to do. This is what I have tried. Do I need to have some method to save cache to storage also?</p>
  
  <pre><code>
  public class Main2Activity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main2);
          String url="https://www.facebook.com";
  
          WebView webView = (WebView) findViewById(R.id.webview_new);
          webView.setWebViewClient(new WebViewClient());
  
          if(!isNetworkAvailable()){
              webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
          }
          webView.loadUrl(url);
      }
  
  
  
      private boolean isNetworkAvailable() {
          ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService( CONNECTIVITY_SERVICE );
          NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
          return activeNetworkInfo != null && activeNetworkInfo.isConnected();
      }
  }
  </code></pre>