Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Forums Advisor I
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10
Accepted Solution

How to close the browser

Hi

I want when i use the close button in my app the browser field that is loading the url gets stop and move to the previous screen. Then how to do this?

How to stop the browser to load the url??

Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: How to close the browser

if(!browserField.back())
{
//                        logFile.log("No Back Page Available");
      Status.show("No Page Available....");

}
else
 {
//                        logFile.log("Back Page Available");
 }

 

Use this, this code will make ur browser field to last open page....

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to close the browser

Just wanted to clarify the comments made by developer_aman_arora and perhaps add some more information.

 

By close button, I presume you mean the button to the right of the trackpad. 

 

By default, if the focus is in the BrowserField, the BrowserField will attempt to process this like the Browser, and it will return to the previously displayed page.  In fact it is possible to go forward and backward in the 'history' of the BrowserField just like you can in the Browser, if you so wish.

 

I am not sure that is what you want to do, in fact I am not sure what you want to do.

 

But in general, I would recommend that you add the BrwoserField to a MainScreen, and in the MainScreen, override keyChar() method.  In there, look for the Escape key and you can process it how you would like. 

 

One option is to see of the BrowserField has focus, and if it does, then see if there is a previous history entry for the BrowserField and go back if there is.  Alternatively, you could just close the screen.  The processing is up to you. 

 

The processing as supplied by developer_aman_arora is, I think, intended to go in the keyChar method,.  Note that the supplied code will actually go back, if that is possible.  If you want to find out if this is possible, look at

<browserField>.getHistory();

 

Sample keyChar code follows:

 

        protected boolean keyChar(char character, int status, int time) {
            // regardless of where we are, Esc will exit
            switch (character) {
                case Characters.ESCAPE:
                    // your code
                    return true;
                default:
                    return super.keyChar(character, status, time);
            }
        }

 

       

 

Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: How to close the browser

She wants to go to previous page i think, thats why i provide this code
Forums Advisor I
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Re: How to close the browser

Thanks Peter and Aman.

I think my question was not clear to you.

In my app there is a menu called close so if i click on close the html page that was loading gets closed and i get the previos screen.

So i got the solution.

    public boolean onClose()
    {
        Html1.this.close();
        UiApplication.getUiApplication().getActiveScreen().close();
        return true;

  }