title: Overriding back button to resume app
body: <p>Below is the pictorial of the problem with my app.</p>
  
  <p><b></b><b></b></p>
  
  <p><strong>THE APP ON STARTUP:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/fz086.png" alt="Snapshot of app while starting"></p>
  
  <p><b></b><b></b></p>
  
  <p><strong>ON 100% PROGRESS:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/O8udC.png" alt="LOADED PAGE"></p>
  
  <p><b></b><b></b></p>
  
  <p><strong>NOW, IF I HIT BACK KEY AND AGAIN RETURN TO APP:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/ccf5B.png" alt="LOADS AGAIN"></p>
  
  <p><b></b><b></b></p>
  
  <p><strong>WHAT I ACTUALLY WANT:</strong> app should resume and not reload when the user returns after pressing back key. </p>
  
  <p>I am sharing the code below. Kindly, suggest a solution.</p>
  
  <pre><code>package com.url.app;
  
  import android.net.ConnectivityManager;
  import android.net.NetworkInfo;
  import android.net.Uri;
  import android.os.Bundle;
  import android.annotation.SuppressLint;
  import android.app.Activity;
  import android.app.AlertDialog;
  import android.app.ProgressDialog;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.content.Intent;
  import android.webkit.ValueCallback;
  import android.webkit.WebView;
  import android.webkit.WebChromeClient;
  import android.webkit.WebViewClient;
  import android.provider.Settings;
  
  
  
  public class MainActivity extends Activity {
  
   private WebView wv;  
  
  //make HTML upload button work in Webview   
   private ValueCallback&lt;Uri&gt; mUploadMessage;  
   private final static int FILECHOOSER_RESULTCODE=1;
  
   @Override  
   protected void onActivityResult(int requestCode, int resultCode, Intent intent) {  
    if(requestCode==FILECHOOSER_RESULTCODE)  
    {  
     if (null == mUploadMessage) return;  
              Uri result = intent == null || resultCode != RESULT_OK ? null  
                      : intent.getData();  
              mUploadMessage.onReceiveValue(result);  
              mUploadMessage = null;        
    }  
   }  
  
   //Check if user is online
   public boolean isOnline() {
       ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
       NetworkInfo netInfo = cm.getActiveNetworkInfo();
       if (netInfo != null &amp;&amp; netInfo.isConnected()) {
           return true;
       }
       return false;
   }
   //if not online show alertdialog with settings button
   public void showNoConnectionDialog(Context ctx1) {
       final Context ctx = ctx1;
       AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
       builder.setCancelable(true);
       builder.setMessage(R.string.no_connection);
       builder.setTitle(R.string.no_connection_title);
       builder.setPositiveButton(R.string.settings, new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int which) {
               ctx.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
           }
       });
       builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int which) {
               return;
           }
       });
       builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
           public void onCancel(DialogInterface dialog) {
               return;
           }
       });
       builder.setCancelable(false);
       builder.show();
   }
  
  
   //supress lint coz it cries over javascript enabled
  @SuppressLint("SetJavaScriptEnabled") @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      //if not online then show NO CONNECTION Dialog
      if(!isOnline()) {
         showNoConnectionDialog(MainActivity.this);
      }
  
      //webview
      wv = new WebView(this);
  
      //loadurl
      wv.loadUrl(getString(R.string.siteurl));
  
  
      //Enable JavaScript
      wv.getSettings().setJavaScriptEnabled(true);
  
      //Zoom
      wv.getSettings().setBuiltInZoomControls(true);
      wv.getSettings().setSupportZoom(true);
  
      //progressdialog
      final ProgressDialog pd = ProgressDialog.show(this, "", getString(R.string.loading), true);
      pd.setCanceledOnTouchOutside(false);
  
      wv.setWebViewClient(new WebViewClient(){
          //hide progressdialog when page loads completely
          @Override
          public void onPageFinished(WebView view, String url) {
              if(pd.isShowing() &amp;&amp; pd!=null)
              {
              pd.dismiss();
              }
          }
      });
  
  
      wv.setWebChromeClient(new WebChromeClient()  {
  
          // For Android 3.0+
          public void openFileChooser( ValueCallback&lt;Uri&gt; uploadMsg, String acceptType ) {  
              mUploadMessage = uploadMsg;  
              Intent i = new Intent(Intent.ACTION_GET_CONTENT);  
              i.addCategory(Intent.CATEGORY_OPENABLE);  
              i.setType("image/*");  
              MainActivity.this.startActivityForResult( Intent.createChooser( i, getString(R.string.fileselect) ), MainActivity.FILECHOOSER_RESULTCODE ); 
              }
  
          // For Android &lt; 3.0
          public void openFileChooser( ValueCallback&lt;Uri&gt; uploadMsg ) {
              openFileChooser( uploadMsg, "" );
              }
  
          // For Android &gt; 4.1
          public void openFileChooser(ValueCallback&lt;Uri&gt; uploadMsg, String acceptType, String capture){
  
              openFileChooser( uploadMsg, "" );
              }        
                  });
        setContentView(wv);      
    }
  }
  </code></pre>
  
  <p><b>PS:</b> the upload button is working in my code, the problem is how do I keep WebView active in background, such that if user starts uploading and exits the app, uploading continues.</p>
  
  <p><b>UPDATE:</b> I think <a href="https://stackoverflow.com/a/3142471/1331135">overriding the back button along with a notification</a> may be useful in this case.</p>