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: 86
Registered: ‎03-06-2010
My Device: 9000/9700
My Carrier: AT&T
Accepted Solution

What exactly happens with a popScreen?

I have the very beginnings of an app, and I was debugging some screens.  When I selected a menu item for which the run function looks like this:

            public void run()
                {
                Contact c= (Contact) contacts.elementAt(listField.getSelectedIndex());
                if (c != null)
                    {
                    RoloContact rc= new RoloContact(c);
                    selectedContact(rc);
                    }
                }

 

 

or, like this:

 

            public void run()
                {
                Contact c= (Contact) contacts.elementAt(listField.getSelectedIndex());
                if (c != null)
                    {
                    RoloContact rc= new RoloContact(c);
                    selectedContact(rc);
                    myApp.popScreen(selScreen);
                    }
                }

 

the screen doesn't disappear (here, myApp is a UIApplication, and, in the first snippet above I have placed myApp.popScreen in the selectedContact function),.  Where I am in the code right now, I don't push another screen on it yet- in fact, it just returns into the event loop and there's nothing else for it to do.

 

 

So, my question is: should the last screen still be visible even though it's popped?  I'll continue experimentation and may get my answer by just playing around, but if I am doing something wrong and, even though I push another screen on top of this one and the top one becomes visible, does that mean that the prior (earlier) screen is still hanging around somewhere, consuming resources?

 

I'll post any further results I have.

 

TIA,

anw

 

TIA,
Allen
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: What exactly happens with a popScreen?

Your screens are kept in a stack container. When you push a screen, it is at the top of the stack and receives focus.

 

When you pop a screen, it is removed form the display stack, and the previous screen is comes to the top. It is displayed and receives focus.

 

If you pop your last screen, your app is closed.

 

Regular Contributor
Posts: 86
Registered: ‎03-06-2010
My Device: 9000/9700
My Carrier: AT&T

Re: What exactly happens with a popScreen?

Hey!  Thanks for the response.

 

So does it appear I have some sort of error then?  I popped the only screen on the stack, and the app didn't close but appeared to just return to its event loop (hard to tell since all that stuff has no source to see in the debugger).

 

The documentation for the screen's "close" function says that, when called, it pops itself, then, if there's no more screens on the stack, it call System.exit.  Based on that documentation, it doesn't sound like popScreen will shut down the application even if it is the last screen on the stack.

 

Since the first post, I've experimented, and after popping the screen in question, I push a very simple dummy screen onto the stack and it displays fine and its UI component (a "Cancel" button whose callback just call System.exit) seems to work fine, but that still doesn't tell me whether or not I still have a corrupted screen lurking somewhere in the bowels of my app.

 

anw

 

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

Re: What exactly happens with a popScreen?

That's an interesting experiment you ran. I think that you are right--closing the last screen will exit the app, but popping the last screen apparently does not.

 

Evidently, handing back an empty stack to the event loop means that the display is not updated with a new screen (at least as long as your app is in the foreground). This leaves the last screen painted on the display. I don't think that you have a corrupted screen lurking anywhere--just the "ghost" of the last screen image still lurking on the display. I haven't tried it, but my guess is that if you switched to another application, the ghost would not reappear when you switched back.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Regular Contributor
Posts: 86
Registered: ‎03-06-2010
My Device: 9000/9700
My Carrier: AT&T

Re: What exactly happens with a popScreen?

That about sums up my thoughts too.  Thanks for the help!

TIA,
Allen