title: how to prevent crash during returning previous activity?
body: <p>I have two activities. Main Activity and Second Activity. I have used a back button in the second activity. In the onclick event, I have used the returnHome() method to finish the second activity and return to the main activity.</p>
  
  <pre><code>    public class SecondActivity extends Activity {
  
      private WebView webView;
  
      public void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                  WindowManager.LayoutParams.FLAG_FULLSCREEN);
  
          setContentView(R.layout.subscribe);
  
          webView = (WebView) findViewById(R.id.webView);
  
          webView.getSettings().setJavaScriptEnabled(true);
  
          webView.loadUrl("http://stackoverflow.com");
  
  
  
  
      }
      class MyWebViewClient extends WebViewClient {
            @Override
  
             public boolean shouldOverrideUrlLoading(WebView view, String url) {
              view.loadUrl(url);
                  return true;
            }
          }
  
      public void returnHome() {
           onBackPressed();
      }
  }
  </code></pre>
  
  <p>But, when I pressed back button, a dialog box will appear stating the below statement with OK button.</p>
  
  <blockquote>
    <p>Unfortunately, application has stopped.</p>
  </blockquote>
  
  <p>How could I prevent/stop this dialog box to smoothly return to previous activity?</p>