Back button in webview

0

I'm starting out in the area of android application development. So I started to develop an application which created 4 layouts (main screen, central subscriber, contact and plans). In the central activity of the subscriber I put a webview and when the client presses the back button of the cell phone you can navigate the pages with this code that I put in the activity java:

Override
public void onBackPressed(){

if (mywebView.canGoBack()){

mywebView.goBack();

} else {

} 

Only when the client browses within the webview and returns to the main web page via the cell button, to that page and does not return to the menu.

I tried to create a back button with startactivity in the header to return to the menu, but it gives error saying "the application has stopped."

Thank you in advance for the help!

    
asked by anonymous 29.06.2017 / 16:12

1 answer

1

If you are not completing the main activity when you start subscriber central activity, you can simply close this second activity to go back to the first activity.

Example:

Override
public void onBackPressed(){
    if (mywebView.canGoBack()){
        mywebView.goBack();
    } else {
        finish();
    }
}
    
29.06.2017 / 16:26