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
New Developer
gmatta
Posts: 23
Registered: ‎10-20-2008
My Device: Not Specified
Accepted Solution

Screen Navigation

I am using JDE 4.5.0.7 and Simulator 8300

 

I have over 7 screens in my application that the user will navigate to and from as they complete their work.  Right now I am creating a new screen each time they navigate to it.  This of course is placing multiple versions of the same screen into the list of screens where they are pushed.

 

What is the best way to handle this situation?  Is there a way to determine if a screen already exists in the list and if so, find it and use it rather than creating a new one eash time?

 

If there is not a way to do this what would the best way to be from a memory and processing stand point?

 

If so pointing me to some examples would be helpful as I am new to this.

 

THANKS

Please use plain text.
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Screen Navigation

Check this link:

 

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&thread.id=13264

 

And look at this link: Blackberry Developer Guide & Other documentation

 

There is helpful information to resolve your issue.

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Screen Navigation

Regardless of the memory/processing used, your first consideration must be what the user wants/expects. 

 

To make this easy, I'm going to call your screens Screen1, Screen2, Screen3, ... Screen7.

 

Typically screens are used in a hierarchical way, so you go from one to the other and escape back, so you will go from Screen1 to Screen2, then Screen3, but never from Screen3 to Screen1.  In this case, it is quite reasonable for you to create a new Screen2 in Screen1, then push it, and when you escapes from Screen 2 (by popping it), the resources used by Screen2 will all be freed and Screen1 will magically appear because it was next on the Display Stack.

 

However if your User can go from Screen1 to Screen2, then Screen3,, then onto Screen1, and so on, creating a new Screen every time will result in a lot of screens.  With this method, the user can escape quite happily back to where they started, which might be what they have to do.

 

If however the user expects to go from Screen1 to Screen2, then to Screen3 then to Screen1 at which point the values from the original Screen1 should be there, then creating new Screens each time is not going to work.  In this situation, you could save all the screens, and perform the screen changes by popping the current screen and pushing the new screen at the same time, effectively swapping the screens on the top of the Display Stack.  But if you do this, you loose the ability to go 'Back'.

 

Ok, on to your specific questions:

 

"Is there a way to determine if a screen already exists in the list"

Yes - Screen.isDisplayed() will tell you that.  I'm not sure how useful it is because it could be buried in the Display Stack and you might have to pop a number of screens to get it back.  You can't have the same screen in two places on the Display Stack.  I've not tried popping a screen that was not on the top of the Stack, that might work and if it did, you would then be able to push the Screen again, effectively moving it to the top of the Display Stack.  Note that it would loose its place when the user backed down the Screens. 

 

"what would the best way to be from a memory and processing stand point"

I would make sure the structure does what the user wants, then try to make it more efficient.  That said, the best thing is to create the screens only once and destroy them when the app is closed.  You can do this in a number of ways, one way I use is to have a Screen manager, and just ask it for the Screen you wanted - the Screen manager will create it and retain it if one is not already created.

 

Hope this helps.

 

Please use plain text.
New Developer
gmatta
Posts: 23
Registered: ‎10-20-2008
My Device: Not Specified

Re: Screen Navigation

Thank you so much Peter for taking the time to explain this so clearly, so effectively and so completely.  I wish I could have found such a comprehensive and clear explanation in the BlackBerry documentation.
Please use plain text.
Developer
simon_hain
Posts: 16,010
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Screen Navigation

i would suggest to create a ui controller that handles all screen navigation.
it is often good to know the status of the application, and if you just use push/pop while you are asking the user for input there may be unexpected results.
or you can use managers instead of screens and handle them all in a single screen.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
ssaidwho
Posts: 17
Registered: ‎12-31-2009
My Device: Not Specified

Re: Screen Navigation

[ Edited ]

If all screen are custom classes, what do you guys think of making them singletons, and regularly popping screens when pushing new ones? I'm am trying this approach out with success so far, but would be curious to hear any comments, particularly how this works with the framework at a lower level. Is it generally better to keep the screen stack small? This makes the 'Back' button useless, of course, but my application's workflow doesn't call for it.

 

Also, with regard to Peter's comment about destroying screens when the application closes - is this not handled by the framework/garbage collection?

 

 

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Screen Navigation

My understanding of the underlying framework would suggest that having a large screen stack impacts the memory usage on the device, but little else.  But that is really just an educated(?) guess.  As I said in the post above, I think about how the user will interact before I worry about the resource usage.

 

With regard to my comment about destroying screens, you are correct that they will normally all be removed by garbage collection when the application terminates. 

Please use plain text.
Trusted Contributor
avi_yach
Posts: 184
Registered: ‎11-26-2010
My Device: Not Specified

Re: Screen Navigation

Hello Simon, I am developing a BB project kind of in an isolated mode, so forums are the only source from which I am learning and implementing stuff. Can you suggest me some links or some example that has a uicontroller? 

 

I tried creating one, but it is no close for production standard. 

 

A Y.

Please use plain text.