title: Intent same activity
body: <p>I have an issue. My program is suppose to go to different IP address with different names inside. It will then take out HTML code from the website. If it does not correspond to the correct name, it will skip to the next URL. </p>
  
  <p>Here is the code for getting the username from the user, and accessing the webpage using webview.</p>
  
  <pre><code>    name = getIntent().getExtras().getString("username");
      URL = getIntent().getExtras().getInt("URL"); //URL passed from previous activity as 99
  
  
  
              webview.setWebViewClient(new WebViewClient() {
                  @Override
                  public void onPageFinished(WebView view, String url) {
                      webview.loadUrl("javascript:window.HtmlViewer.showHTML" +
                              "('&lt;html&gt;'+document.getElementsByTagName('html')[0].innerHTML+'&lt;/html&gt;');");
  
  
  
                  }
  
                 /* public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
  
                      Toast.makeText(getApplicationContext(), "Your Internet Connection May not be active Or " + error, Toast.LENGTH_LONG).show();
                      URL = URL +1 ;
                      Intent intent = new Intent (lightingpair.this, lightingpair.class);
                      intent.putExtra ("username", name) ;
                      intent.putExtra ("URL", URL);
                      startActivity (intent) ;
  
                  }*/
              });
  
              webview.loadUrl("http://192.168.0." + URL + "/pair");
              Toast.makeText(getApplicationContext(), String.valueOf(URL) , Toast.LENGTH_LONG).show();
  </code></pre>
  
  <p>This is the code for the javascript</p>
  
  <pre><code>class MyJavaScriptInterface {
  
      private Context ctx;
  
      MyJavaScriptInterface(Context ctx) {
          this.ctx = ctx;
      }
  
      String nhtml;
      @JavascriptInterface
      public void showHTML(String html) {
  
          nhtml = html ;
  
        runOnUiThread(new Runnable() {
              @Override
              public void run() {
  
                  if (nhtml.indexOf(name) &gt; 0) {
                      Intent intent = new Intent(lightingpair.this, Lighting.class);
                      intent.putExtra("username", name);
                      intent.putExtra("url", URL);
                      startActivity(intent);
                  } else {
  
                      URL = URL + 1;
                      Intent intent = new Intent(getApplicationContext(),lightingpair.class);
                      intent.putExtra("username", name);
                      intent.putExtra("URL", URL);
                      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                      intent.putExtra("EXIT", true);
                      startActivity(intent);
                  }
              }
  </code></pre>
  
  <p>However, it stops after scanning after 3 or 4 webpages, sometimes it scans more. 
  Was wondering whether there is a more efficient way to go to different IP address to collect HTML code. </p>