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();
}
}
Related
I am using xamarin forms prism.
Quick info : I have a page that contains information, this page the user can delete along with its information, this page is an instance of a page called saved conversation, think of each instance as a saved email, you may have many of the one type and are made dynamically.
The user deletes one saved conversation and this also removes an instance for that page, after they have deleted it, it will send them back to one of two pages every time. But they are still able to access this deleted saved conversation page using the hardware back button (Android), either by clicking it straight after they were force navigated back or navigating the app a bit and then pressing the back button multiple times. I would use something such as...
protected override bool OnBackButtonPressed()
{
return true;
}
But I want the back button to work for other pages and only not work if the previous page is an instance of the Saved conversation page, regardless if it has been deleted or not (As I think I may be able to figure out if it was deleted or not myself, just need to detect the page the hardware back button is going to send the user to, I think).
This might fall under a user experience decision over a technical workaround; but it sounds to me like this page you have might be a good candidate to be a Modal Page.
Navigating away from the modal page (popping it from the stack) should accomplish the same goal you are aiming for: not being able to navigate "back" to that page.
What I have done was add this code to all the pages in which I did not want the user to be able to go back. But it would only limit them from going back if the previous page is one of the two shown below. If it isn't then the back button works.
What I did note was you have to make sure modalNavigation is set to false when navigating to the pages (in my case conversation and saved conversation) otherwise they won't appear on the navigation stack to check against.
/// <summary>
/// Will override the harware back button.
/// </summary>
/// <returns> True if it can't go back false if it can.</returns>
protected override bool OnBackButtonPressed()
{
int count = this.Navigation.NavigationStack.Count;
bool shouldntGoBack = false;
if (count > 1)
{
string previousPage = this.Navigation.NavigationStack[count - 2].ToString();
if (previousPage == "NGT.Views.ConversationPage" || previousPage == "NGT.Views.SavedConversationPage")
{
shouldntGoBack = true;
}
}
return shouldntGoBack;
}
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
...
}
I have an activity that loads content from the internet when it initially loads, however the order it takes is:
1) User hits button to go to new activity
2) App stays on old activity
3) App loads content from internet (usually takes about a second or two)
4) App brings user to new activity with content already loaded
Now this is fine, however it can be confusing for a user because while they are still on the original activity, there is no indication that their input did anything. If the user were to click the button again, it wouldn't register that as another click on the original activity, it would register that as a click on the new activity which is still loading, which may cause a user to end up somewhere they did not wish to be.
I'd like to be able to fix this by having the order of the process be:
1) User hits button to go to new activity
2) Old activity disappears, brings user to "blank" new activity without content loaded
3) Display a loading wheel
4) App loads content from internet
5) Content is displayed and loading wheel disappears.
However I can't figure out how to accomplish this, I placed all my code in the onResume() method because I thought that would work, but the content loaded the same way as it always has, does anyone have any suggestions on how to accomplish what I want? Here is the code in my onResume() method:
protected void onResume() {
super.onResume();
setContentView(R.layout.coupon);
//method call to access the URL needed to display the content
accessURL(Global.contentURL);
}
Any help would be greatly appreciated.
You can use an AsyncTask that creates a ProgressDialog while it fetches the data in the background. There are many questions about this on SO (e.g. How to use AsyncTask to show a ProgressDialog while doing background work in Android?) as well as on the Internet.
I am developing an application which initially loads a listview of items within onPostExecute. There was no problem opening fuller details on webview (still within the onPostExeceute) after item is selected. However, hitting the goback button within the webview just exits the whole application.
Can someone please help.
The scheme of events is thus
Activity Create establish network broadcast --> onStart --> AsyncTask --> retrieves data --> onPostExecute --> setContentView (ListView) --> onClickListener --> WebView --> goback button at this stage then exits the entire application.
I'm sure someone can help me on this and I would really appreciate any effort.
Regards
This behavior is normal. onBackPressed() event call finish() method in your activity and throw you back to where you just start from.
You still have the possibility to catch this event and tell your app what to do at next
The default behavior of the back key in Android is to return the previous Activity, or if you are already at the root Activity, to exit the app. It sounds like your WebView is located within the same Activity as your ListView, so when you are clicking the "Back" key the app is exiting because there is no previous Activity to return to.
One solution would be to create a new Activity for displaying the WebView and pass in the data that you want to be displayed. With the WebView being loaded in a separate Activity, pressing the "Back" button will finish the WebView Activity bring you back to the list. You also get the added benefit of having screen transitions this way.
Another solution is to override the onKeyUp method in the ListView Activity and handle the pressing of the back key manually. (I personally recommend onKeyUp instead of onKeyDown because it makes it easier to handle long press that way) Capture the event and just undo whatever you are doing when an item in the list is clicked.
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.