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: 89
Registered: ‎05-31-2010
My Device: 8100
My Carrier: tmobile
Accepted Solution

Return to main Screen

Hi...

 

i have 3 screens... when the user make click in a button in the screen A... i send to screen B... and when the user make click in a Button in this screen i send to screen C.

 

Now i need put a buttton in the screen for what the user can return to screen A.. home. if i use the key "arrow back" from the device return to screen B. and later Screen A.. so what i can do?

Developer
Posts: 85
Registered: ‎05-03-2010
My Device: Not Specified

Re: Return to main Screen

[ Edited ]

Ok i'm assuming that by "arrow back" you mean the Escape key. You need to implement the keyChar method in your screens and then popScreens accordingly. Something like this

 

 

protected boolean keyChar(char ch, int status, int time)
{
    if(ch==Characters.ESCAPE){
        UiApplication.getUiApplication.popScreen(this);
    }
}

 

PS. You'll have to put that code in all the screens. Now, i'm thinking that if you have a screen that extends MainScreen and has the above keychar method like this

 

protected boolean keyChar(char ch, int status, int time)
{
if(ch==Characters.ESCAPE){
UiApplication.getUiApplication.popScreen(UiApplica

 tion.getUiApplication().getActiveScreen());

}
}

And then you inherit all your screens from this parent screen, that should do the trick too. I'm not sure but its worth trying.

 

Regular Contributor
Posts: 89
Registered: ‎05-31-2010
My Device: 8100
My Carrier: tmobile

Re: Return to main Screen

OK but whit this code i return to the screen C to B... how i can return to screen C to A?

Developer
Posts: 85
Registered: ‎05-03-2010
My Device: Not Specified

Re: Return to main Screen

[ Edited ]

you want to return from C to A using the back arrow key (ESCAPE key)?

If so, in the keyChar method of screen C, if the char equals ESCAPE, push screen A.

Regular Contributor
Posts: 89
Registered: ‎05-31-2010
My Device: 8100
My Carrier: tmobile

Re: Return to main Screen

[ Edited ]

No i need put in the menu an option for return from C to A

Developer
Posts: 85
Registered: ‎05-03-2010
My Device: Not Specified

Re: Return to main Screen

Ok, I haven't used the menu's a lot but here's a modified snippet from Anthony Rizk's book Beginning Blackberry Development. If you want this option only on Screen C, create an internal Class within your screen, extend it to MenuItem and then override the makeMenu method of the screen. something like this.

 

 

class HomeMenuItem extends MenuItem {
	public HomeMenuItem() {
	    super("Home", 20, 10);
	}
	public void run() {
	    //push screen A here
	}
}
	
protected void makeMenu(Menu menu, int instance) {
	super.makeMenu(menu, instance);
	menu.add(new HomeMenuItem());
}

 

 

Regular Contributor
Posts: 89
Registered: ‎05-31-2010
My Device: 8100
My Carrier: tmobile

Re: Return to main Screen

I have this item in the menu from the screen C.. so what i can do, for send the user to Screen A (main screen)?

 

 

 	private MenuItem _home = new MenuItem("Recomendados", 110, 10) {
		public void run() {
			UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());

		}
	};

 

 

Developer
Posts: 106
Registered: ‎06-18-2009
My Device: Bold

Re: Return to main Screen

okay....with out of some sort of framework in place that allows you to easily navigate between screens, you coudl simply pass a reference of A to both B and C.  So whenever you need to navigate back to A, you can check if A is on the display stack with isDisplayed first and if so pop it (because you cannot push a screen that is already on the stack) and then push A (back) onto the top of the display stack.

 

I'm not familiar with a way to get a screen that is somewhere on the display stack to the top of the stack.

 

Of course in this case you would also have to manually remove B and/or C so that when the user hits the ESCAPE key on A, the application closes instead of the user going back to B or C (depending on which screen is below A on the display stack).

 

Does that make sense?

----
If this helped you, press the thumbs up button (on the far right - '+' thumb icon)
If this post solved the issue, click "Accept as Solution"
Highlighted
Developer
Posts: 85
Registered: ‎05-03-2010
My Device: Not Specified

Re: Return to main Screen

[ Edited ]

Hmm, nice point by filiussoft. Although i'm not sure how exactly can one get the reference of the screen. I do it by defining static screens before i push them. Don't know if thats the best way to do it, but works for me. So here's something you can do

 

 

private MenuItem _home = new MenuItem("Recomendados", 110, 10) {
public void run() {
if(screenA.isDisplayed())
UiApplication.getUiApplication.popScreen(screenA);

UiApplication.getUiApplication.pushScreen(screenA);
}
};

 

And I found a gem of a post by peter_strange and I quote

 

"Finally, if you have something like a Home button, the user expects all screens to be removed from the stack so that you are left with the initial screen only.  Normally you wil do this by popping off all the screens except the first one on the stack."

 

Complete post:

http://supportforums.blackberry.com/t5/Java-Development/Bring-back-the-screen-to-the-top/m-p/383513/...