Why my onBackPressed() method is not working for me?

A

AC Question

Please some one help me to understand I am building a simple WebView app and have override method OnBackPressed() to just make the functionality to go back if some one touches back button. Unfortunately my app closes with error "App has stopped working" meanwhile android studio also shows some run-time errors. My code is as below : -

@Override
public void onBackPressed()
{
if (view.canGoBack())
{
view.goBack();
} else

{
//otherwise exit my app
super.onBackPressed();
}
}

I dont know what is wrong please some one clear my point.
 

Justify23

Member
Feb 5, 2017
15
0
0
Visit site
to go back to where? if you're referring to another activity you should initiate an intent and call the activity you wanted to go back. the code you provided doesn't provide much as you didn't include what view you are referring to.
 

Forum statistics

Threads
949,944
Messages
6,945,023
Members
3,161,713
Latest member
Rosahitt