I have a WebView and i using WebView.goBack() when tap back button and i using WebView.goBackOrForward(x) in another place.
My question is that why WebView.goBackOrForward(x) loads visited web page again from internet but WebView.goBack() does not load visited web page again and shows previous web page quickly?
As in the doc:
goBack
Added in API level 1
void goBack ()
Goes back in the history of this WebView.
instead
goBackOrForward
Added in API level 1
void goBackOrForward (int steps)
Goes to the history item that is the number of steps away from the current item. Steps is negative if backward and positive if forward.
I assume that knowing exactly which page WebView is going to load make it faster as with goBack it always load the previous page. goBackOrForward need to calculate which page it need to load before loading it. I'm not sure about that, you should check the code.
Related
I'm junior of android developer. (super beginner T_T)
I'm having trouble with Android Webview.
I am making a Hybrid app.
- when touch the app icon, it is linked to the webview(webview.loadurl(url)) directly.
When I click the home button after loading url and searching the web page (which is loaded through the webview),
and then re-click the app icon or touch the webview processing through click the home button long~.
I want to keep the page I've seen right before click the home button.
but It doesn't work.
Just reload the main index page.
I want...
Index page(login.jsp) -> A page -> B page -> Home button -> re-click the app or ~ -> B page
but unfourtunately, it works
Index page(login.jsp) -> A page -> B page -> Home button -> re-click the app or ~ -> Index page -> back key -> B page... It really strange.. \T_T
(back key -> B page :: Session didnt fired. may be keeped.)
I searched a lot about these problems.
Many people answered - Using Cookies and keep the session. but it also didn't work for me.
I know I didnt explain current problem well and show the code to you.
but I really really need help .
So please give me any hint.
Do I have to save the url adress which I searched last.?
Just to make sure we're talking about the same thing: when you say "home button," you mean the Android home button, not something on the web page, right?
When you press the home button, your activity is stopped; and it is restarted when the user returns to your app. The activity does not necessarily get destroyed and recreated, but it could, in which case the state is lost (except for state that the activity automatically saves).
I don't know about webview specifically, but if your activity is losing important state, such as the URL of the B page, you can save and restore it by overriding onSaveInstanceState() and onRestoreInstanceState().
I have built a Meteor app with a mobile app interface (using Ratchet), only designed to be run as an app. On each page, there is a "back" link that takes you back to the parent page. For example, if I go deep inside a hierarchy of page such as this one:
Home > Category > Post
I can use a link in the Post page that will take me back to the Category page. Now, the problem is, if from this Category page I hit the back button, it should have the same behaviour as clicking the back link on the page. (in this case, take me to the Home page) Sadly, this doesn't happen and I get taken back to the Post page.
On iPhone it is not a problem (as far as I know) since there is no actual back button built-in to the device. But on Android it gives me headaches, for example:
Say a user goes to a Post page that he can delete using a button shown on the page. When the post-deletion method finishes, I take the user back to the Category page:
Router.go('categoryPage', {'_id': categoryId});
Problem is: if the user hits the back button after deleting a post, he or she gets taken to a "not found" page, since the previous post has been deleted. Now I can avoid that by adding replaceState: true like this:
Router.go('categoryPage', {'_id': categoryId}, {replaceState: true});
But now when the user hits the back button from the Category page, he or she gets taken to the page that was there before the Post page, which was... the same Category page. So the button just does nothing on the first press.
I also tried to pushState the url of the desired page in each of my template's `rendered̀€ function, to no avail (and what would I put in there for the Home page?):
Template.categoryPage.rendered = function () {
history.pushState(null, null, Router.url('home'));
};
Template.postPage.rendered = function () {
history.pushState(null, null, Router.url('categoryPage', {'_id': this.data.categoryId}));
};
Has anyone tackled this issue and/or would be able to drop some knowledge?
As soon as the back button is pressed, Cordova trigger a "backbutton" event, see there.
By listening to this event you should be able to override the default behavior and do what you want:
document.addEventListener("backbutton", onBackButtonDown, false);
function onBackButtonDown(event) {
event.preventDefault();
event.stopPropagation();
// Do what you want
...
}
On android WebView documentation it was written that:
"public void clearView ()
Added in API level 1
This method was deprecated in API level 18.
Use WebView.loadUrl("about:blank") to reliably reset the view state and release page resources (including any running JavaScript)."
But I couldn't found any solution to remove the "about:blank" url from the history stack. Then when you pressing back button you have to stop on the "about:blank" url.
For my case I need to reset the WebView state and release page resources but should keep the history without "about:blank" url(s).
PS: clearHistory() clear all history, so it is not my solution.
I have an Activity, in which I've used WebView.
I am loading given server URL in it. Its all working fine. There are several pages in it which I can navigate through.
In one of the page of Website (server URL), for example 'Product Description', there is a button named "Try This", which is basically to try the product that user can have a try.
When user touches this button, using JavaScriptInterface, I am calling one JavaScript function and getting the image URL and loading this in another Activity.
But when I presses the back button from this child Activity, its gets redirected to the very first page of the WebView i.e list of products, but not the last page that I visited.
How can I fix the back button navigation for this?
Second scenario, I've used is using custom dialog, in which I am able to load the picture successfully. What I want is the ability to have user interaction in this custom dialog. For Example, is it possible that user can drag, move, zoom, resize and capture picture from camera all in this custom dialog box? How can I achieve this, if it's feasible?
Third case, which I don't know exactly is to use Fragments.
Please suggest me how can I overcome this situation.
It would be best if I can use Activty without having back button navigation issue from the child activity.
lazy solution is to override the onBackPressed.
public void onBackPressed (){
if (webview.isFocused() && webview.canGoBack()) {
webview.goBack();
}
}
Hi i am having a activity with a button, on click of the button it has to load a custom browser in a new activity not the default browser of android. and i need a way to exclude the history of the browser such that on back press it comes back to the previous activity without navigating to previous website. I am new to android and any ways to do this
You are probably just talking about the WebView
Link to the official tutorial
Note :
This onKeyDown(int, KeyEvent) callback method will be called anytime a
button is pressed while in the Activity. The condition inside uses the
KeyEvent to check whether the key pressed is the BACK button and
whether the WebView is actually capable of navigating back (if it has
a history). If both are true, then the goBack() method is called,
which will navigate back one step in the WebView history.Returning
true indicates that the event has been handled. If this condition is
not met, then the event is sent back to the system.
You can start by putting a WebView in an activity.
If you want to have a view which can browse the web in your app then make use of the WebView view.
Else if you want to create your own custom browser, then you have to make use Web engine WebKit present in the library layer of the android.