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
Developer
Posts: 154
Registered: ‎01-08-2010
My Device: 8310 Rogers

How to prevent screen navigation using blackbrerry "back" key?

[ Edited ]

Hi

 

We have a small blackberry application having few screens.

 

The Blackberry’s back button  navigates back through previous screens and ultimately navigate the user right back to the Blackberry desktop. 

 

This button should not transition any screens within the application.  The user should only be able to use it to switch out to the desktop, but application should continue to run in the background and maintain its current screen state if the user goes back into the app.

 

How can we achieve this?

 

Please help?

 

Thanks in advance.

Developer
Posts: 65
Registered: ‎01-05-2010
My Device: Not Specified

Re: How to prevent screen navigation using blackbrerry "back" key?

[ Edited ]

override onClose() in your Screen object and return false

 

As an example only, here is what I have in my applications screen object.  It doesn't do specifically what you need but it demonstrates overriding the behaviour of the back button.

 

public class AppScreen extends MainScreen {
	NavigationManager navigation = null;
	protected boolean onSavePrompt() {
		return true;
	}
	public boolean onClose() 
	{
		if (null != navigation) {            // does what I want back to do
			if (navigation.stack.size() > 1) {
				navigation.pop();
				return false;
			}
		}
		App.instance.cleanupBeforeExit();   // my cleanup code
		close();	// Never returns?
	    return true;
	}
	public void registerNavigation(NavigationManager navigation) {
		this.navigation = navigation;
	}
}

You wouldn't want to call close I don't think but something else that puts you into background.

 

Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook

Re: How to prevent screen navigation using blackbrerry "back" key?

you could also override keyDown to catch the back key and discard it (this will also work for any key)

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

Re: How to prevent screen navigation using BlackBerry "back" key?

[ Edited ]

An easier (in my opinion) way to do this is to override keyChar and swallow all Keypad.KEY_ESCAPE characters.

 

Edit: didn't see CMY's post before putting thjis in.  The two methods are identical really, but I prefer using keyChar to keyDown. 

Developer
Posts: 154
Registered: ‎01-08-2010
My Device: 8310 Rogers

Re: How to prevent screen navigation using BlackBerry "back" key?

Hi

 

Could you please give an sample code for keyChar or keyDown?

Developer
Posts: 68
Registered: ‎02-05-2009
My Device: Not Specified

Re: How to prevent screen navigation using BlackBerry "back" key?

 

protected boolean keyDown(int keycode, int time) {
  if(keycode == Keypad.KEY_BACKSPACE)
     return true;
}

 

Should be something like that. I did not test it but it should work or be VERY close to what you want.

 

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: How to prevent screen navigation using BlackBerry "back" key?

Also, if you want to minimize the application and run it in the background, you will need Application.getApplication().requestBackground().  Add that to the desired special key handling in your keyDown/keyChar methods.

 

Regards,

    Arkady.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 154
Registered: ‎01-08-2010
My Device: 8310 Rogers

Re: How to prevent screen navigation using BlackBerry "back" key?

Hi

 

 

protected boolean keyChar(char c, int status, int time) {
		// TODO Auto-generated method stub
		if (c == Keypad.KEY_BACKSPACE) {
			return true;
		}
		return super.keyChar(c, status, time);
}

 

 

I tried above code but it did not work.

 

Please help.

 

Thanks

 

Developer
Posts: 154
Registered: ‎01-08-2010
My Device: 8310 Rogers

Re: How to prevent screen navigation using BlackBerry "back" key?

I tried this too but with no success.

 

 

protected boolean keyDown(int keycode, int time) {
    if(keycode == Keypad.KEY_BACKSPACE)
      return true;
    return super.keyDown(keycode,  time);
}

 

 

Developer
Posts: 154
Registered: ‎01-08-2010
My Device: 8310 Rogers

Re: How to prevent screen navigation using BlackBerry "back" key?

Hi

 

Basically back button should work like exit button. When i click on back button control should go to blackberry desktop (like red exit button).

 

 

At this point when i again start my app it should remember the last screen and show the same screen.

 

This is happening when i click on exit button and not when i click on back button.

 

Pleas help.

 

Thanks.