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
New Developer
Posts: 85
Registered: ‎12-02-2013
My Device: 9360 Curve
My Carrier: BSNL
Accepted Solution

How to Display previous screen when browser eventually closed.

Hello everyone,

 

I am working on an application in which user opens a screen and click on a button, when user pressed this button he/she redirects to phone browser with a specified link. but i am facing a problem in that, when eventually user close browser without completing specified action my screen also poped off from UI. My concern is that if user shut down or close browser without completing action it should display previous screen. please suggest me how to do this......

 

here is the code

ButtonField checkUpdate = new ButtonField("Update", ButtonField.CONSUME_CLICK);

FieldChangeListener updateListener = new FieldChangeListener() {
            
            public void fieldChanged(Field field, int context) {

                                             BrowserSession browserSession = Browser.getDefaultSession();
                                            browserSession.displayPage("http://www.xyz.com");

 

}

};

checkUpdate.setChangeListener(updateListener);

 

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

Re: How to Display previous screen when browser eventually closed.

[ Edited ]

What you are asking may happen by accident most of the time, but can not be forced to happen. 

 

Typically what happens is that the user will start your application, be redirected to the Browser, finish whatever they are doing in the Browser, and then close the Browser.  The BlackBerry OS then needs to choose the next application to display, it does this in reverse order  of activity, so yours is the next application to be displayed.

 

But the Blackberry OS runs applications, and your application is just one.  From any application the user can switch to another application - one way is using the "switch application" menu item on most menus.  You can't stop the user switching applications like this while they are in the Browser, so they can alter the order in which the OS displays applications and so your application may no longer be the one displayed when the user closes the Browser. 

  

An example should explain.  Say the user starts your application, then goes into the Browser.  They then switch application to another one.  After this action, on the 'stack' of applications to be displayed, there is your application, the Browser, and then this other application on top.  Say the user then switches application back to the Browser.  Now the application stack has your application on the bottom, the other application and the Browser on top.  if the user now closes the Browser, they will see the other application, not yours. 

 

Given this information, I hope you understand that this statement is not correct:

"when eventually user close browser without completing specified action my screen also popped off from UI.". 

What has probably happened is that your application is no longer the next active one after the Browser.   Apparently your UI has been closed, but it has not,

 

And just to repeat, there is nothing you can do about this. 

 

So if you want to control this behavior, then instead of using the Browser (a separate application) to display your web pages, you have to use a BrowserField - then the 'browser' screen the user sees is actually in your application. 

 

There are quite a few samples of using BrowserField if you search here, and this is a good place to start:

http://supportforums.blackberry.com/t5/Java-Development/BrowserField-Sample-Code-Create-your-first-B...

New Developer
Posts: 85
Registered: ‎12-02-2013
My Device: 9360 Curve
My Carrier: BSNL

Re: How to Display previous screen when browser eventually closed.

Thank you very much peter for such a great and detailed suggestion, i will surely follow this. And one more question peter can we set multiple screen to background using requestBackground() method?

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

Re: How to Display previous screen when browser eventually closed.

Some clarification is required before I answer the question. 

 

requestBackground() is issued against the application currently running, not a screen.  So the application that will 'requestBackground()' is your application (unless you have done something very complicated!).  If you call requestBackground() in your application, then the BlackBerry OS will put your application at the bottom of the application stack, and will use the application stack as I described previously to decide which application's screen to display. 

 

In your application (in fact in any application), there is only one screen displayed at a time.  The BlackBerry OS maintains a screen stack for your application, so the top screen hides the ones below.  When the top screen is popped off, the one below is displayed. 

 

Now back to your question:

"can we set multiple screen to background using requestBackground() method?"

 

I hope you now understand my answer, which is, you can set all your application's screens to the background - but in reality, from the user's perspective, you are only sending one screen to the background, since that is all they see (users do not see the other screens on the application's screen stack until the top one is popped off). 

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

Re: How to Display previous screen when browser eventually closed.

Just to be complete, I should add that

 

1) If you are on "friendly terms" with another application, given the right circumstances, it is possible to requestBackground() to the other application.

2) It is possible to have multiple entry points to the same application, in which case it can look to the user that one application has multiple screens active at the same time.

 

But these are 'edge' cases that are seldom used and require some detailed understanding of the BB Application architecture.  The comments made above will apply to 99.9% of applications.