Reputation: 13
I have an activity contains WebView and I'm passing URL while opening, Like this:
Intent activity = new Intent(getApplicationContext(),NewActivity.class);
activity.putExtra("URL", url);
startActivity(activity);
When we press back button it closes all previous activities and return to MainActivity so I overrided onBackPressed.
@Override
public void onBackPressed() {
finish();
}
and it still close all previous activities.
Note : It declared in manifest like this:
<activity
android:name=".views.activities.NewActivity"
android:screenOrientation="portrait"/>
What is the wrong with it?
How can i fix this, I just want to open previous activity onBackPressed
and finish current one.
Upvotes: 1
Views: 147
Reputation:
Try to exit view.
@Override
public void onBackPressed() {
System.exit(REQUEST_CODE);
super.onBackPressed();
}
Upvotes: 0
Reputation: 5534
if I understood correctly you want to navigate to previously loaded webpages in your WebView
rather than closing it from current page.
if that's true try this solution.
@Override
public void onBackPressed() {
if (webView.canGoBack()) {
webView.goBack();
} else {
super.onBackPressed(); // or finish();
}
}
Upvotes: 2