Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Back button on webview kills app
    primarykey
    data
    text
    <p>*Solved I just had to publicly declare my webview variable for my back button class to work correctly. Thanks for the help</p> <p>I've got a unique setup with the webview class and everything I've googled I've gotten nowhere. </p> <p>I'm using buttons to launch webview's and I'm getting the issue that when I press the back button to return to my main app screen it will just kill the app. I have added some code in at the bottom to try and fix my issue but it has not worked.</p> <p>btw the below code has been updated to what is currently working for me.</p> <pre><code>package my.android.test; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.webkit.WebView; import android.widget.Toast; public class MobileAppActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } WebView wb; public void onMyButtonClick01(View view) { Toast.makeText(this, "Pay your dues here!", Toast.LENGTH_SHORT).show(); wb = new WebView(this); wb.loadUrl("http://www.link1.html"); setContentView(wb); } public void onMyButtonClick02(View view) { Toast.makeText(this, "Re-Sign here!", Toast.LENGTH_SHORT).show(); wb = new WebView(this); wb.loadUrl("http://www.link2.html"); setContentView(wb); } public void onBackPressed () { if(wb != null) { if(wb.canGoBack()) { wb.goBack(); } else { setContentView(R.layout.main); wb = null; } } else { super.onBackPressed(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload