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
Regular Contributor
Posts: 64
Registered: ‎02-03-2010
My Device: Bold
My Carrier: Orange
Accepted Solution

Getting the even of returning from browser to application

Hi , I am using 

BrowserSession.showBrowser()

to navigate to a browser from my application ( I wanted to embed the browser in my application, but since i'm compiling for pre 5.0 devices, i  can't use the new browser.field2, but only the not so very impressive browser.field API ).

 

Thing is - I want to perform some stuff once the users comes back to the application from the browser. Is there any way to somehow get this event? ( Once the user presses the back key, he returns to my application from the browser ). 

 

I want to differentiate this event from any other foreground-background event. 

 

Thanks

 

Dan

Highlighted
Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Getting the even of returning from browser to application

Here's one way to do it:

  1. In your UiApplication subclass, declare a Runnable field (let's call it "pending").
  2. Just before calling BrowserSession.showBrowser(), set pending to a Runnable that you want to execute on return.
  3. Back in your UiApplication subclass, override activate():
     
    public void activate() {
    if (pending != null) {
    invokeLater(pending);
    pending = null;
    }
    }

    Using invokeLater isn't strictly really necessary because activate() is called on the event thread. However, I suggest using it anyway just to be sure that the Runnable is executed after any other events that may be pending.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: Getting the even of returning from browser to application

Just to expand a little on Ted's solution, and suggest another option.

 

When you invoke the Browser, your application is pushed into the background.  When an application is pushed to the background, the Application deactivate method is invoked.  When it is bought to the foreground, the activate method is invoked.  So Ted is basically suggesting you set a flag that the activate method checks and if the flag indicates that you pushed to the background by thee Browser, you can do some additional processing.

 

You can actually do something similar at the Screen level.  When a Screen is covered up by anything, its onObscured method is invoked.  onExposed is called when it is displayed again.  So you can have a similar flag and do some processing that Ted suggested in the activate method, in the onExposed method. 

 

You should be aware that onExposed is called frequently, for example whenever a menu is invoked. 

 

Personally I prefer the onExposed, because the processing is usually specific to the Screen, and so this provides an easy way to localize the processing.  But there are merits in Ted's approach as well.  So you choose.

Regular Contributor
Posts: 64
Registered: ‎02-03-2010
My Device: Bold
My Carrier: Orange

Re: Getting the even of returning from browser to application

Thanks guys. I'll probably use Ted's solution, I think it should work for me.

Kudos for all! Smiley Happy

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Getting the even of returning from browser to application

If it works for you, don't forget to mark Ted's post as a solution.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!