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

Regular Contributor
Posts: 98
Registered: ‎03-10-2011
My Device: 9700 Bold

Closing a screen

Hi I am in the process of developing an application which utlisizes buttons to load new screens. I am using a screen transition technique with the following:

protected boolean navigationClick(int status, int time) {
	UiEngineInstance engine = Ui.getUiEngineInstance();
	UiApplication ui = UiApplication.getUiApplication();

	TransitionContext transitionContextIn = new TransitionContext(TransitionContext.TRANSITION_FADE);
	transitionContextIn.setIntAttribute(TransitionContext.ATTR_DURATION, 3000);
	TransitionContext transitionContextOut = new TransitionContext(TransitionContext.TRANSITION_FADE);
	transitionContextOut.setIntAttribute(TransitionContext.ATTR_DURATION, 3000);

	engine.setTransition(null, newScreen, UiEngineInstance.TRIGGER_PUSH, transitionContextIn);
	engine.setTransition(newScreen, null, UiEngineInstance.TRIGGER_POP, transitionContextOut);

	return true;


This code pushes a newScreen in a new java class as follows:


public class Arsenal extends MainScreen implements FieldChangeListener {
	public Arsenal()


My question is, when I push the back button to go to back to the previous menu, I would like the close the screen previous screen, so that if I click on the screen again it reopens at the top, as presently if i press the "back" button on the blackberry, then re click on the button it loads the page from wherever I previously scrolled down to. How do I ensure the screen closes when the "back" button is pressed 



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

Re: Closing a screen

Am I right in saying this actually has nothing to do with the transition?  if you take out that code and just do a push, the same thing will occur?


Even though a screen is not on the display stack, it still retains its 'attributes', such as its current scroll position. 


So if you do not wish to recreate the screen each time, then you need to adjust the scroll position.  The easiest way is just to focus on the top Field in this screen, and if you want to do this generically, then you can programmatically find this by scrolling through your Fields and Managers.  However this may not focus on the top of the screen if there is a none focusable Field at the top of the screen.  In addition, there might be issues if you have scrollable Managers inside the scrollable screen.  But if you can get away with just focusing on the first Field in the screen, this is the easiest option.


Now the question is where do you do this.  The best place I suspect is in the onDisplay or its replacement