views:

170

answers:

1

I have a link in my application that triggers a webview to open from webview.loadUrl(...).

Sometimes it's takes quite a while to load the page, and in these cases I want to be able to use the built in back button on the phone to cancel the loading and go back to my application.

How do I do this? Is there some way I can listen to the backbutton while loading the url?

A: 

The back button is intended to move the user backwards through the activity stack.

I think it is possible you are handling too many user actions in a single Activity. As a general rule, any kind of user 'select' should trigger a new Activity.

Whenever the user does something that should be cancelable with the back button, you should trigger a new internal Activity via an Intent. Then the OS will give you this behavior automatically.

Jim Blackler
The problem is that I have a Progessbar that shows the process of the page loading. So when I click BACK, it steps back from the Progressbar but is still in the webview. So I have to press BACK twice to go back to my appliaction. Is there a way to step back to the former activity in code? The backbutton does it automatically but I need to force it to jump back one more step in the Activity stack.dialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { dialog.cancel();//Code here to go back to former activity } });
Sara
OK I've discovered that overriding the BACK key is more common than I had realized .. check http://android-developers.blogspot.com/2009/12/back-and-other-hard-keys-three-stories.html
Jim Blackler