2

I want to come to home screen when clicking on the back button from my application in blackberry. I have searched for this in google and stackoverflow, But I didn't get any solution. Anybody help for this.

In My Starting Screen i wrote like this for back button.

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

        else
        {
            return super.keyDown(keycode, time);
        } 
    }

In my HomeScreen i wrote like this.

protected boolean keyDown(int keycode, int time)
    {
        if (Keypad.key(keycode) ==  Keypad.KEY_ESCAPE)
        {
            UiApplication.getUiApplication().pushScreen(new StartingScreen());
            return true;
        }

        else
        {
            return super.keyDown(keycode, time);
        } 
    }

From my application HomeScreen I am able to come to starting screen of the my application. after that when i click on back button from starting screen i need to go to blackberry home screen that means i need to exit the app and come out of that. I wrote close(); to come to blackberry home screen. but its not working. it is again coming to my application homescreen.

8
  • what do you mean by home screen ??? Your application home screen or blackberry home screen ??
    – BBdev
    Jun 4, 2012 at 11:57
  • i need to go to blackberry home screen Jun 5, 2012 at 3:46
  • then when you press the back button just close your application.
    – BBdev
    Jun 5, 2012 at 5:30
  • i wrote but its not working.please check my edit.now.like that i have written.but its not working. Jun 5, 2012 at 6:17
  • @sandhya.M. Use System.exit(0); for terminating the application when back key is pressed. protected boolean keyDown(int keycode, int time) { if(keycode == 1179648){ System.exit(0); } return super.keyDown(keycode, time); }
    – Nilanchala
    Jun 5, 2012 at 7:24

3 Answers 3

5

Override keyDown method in your subclass of MainScreen.

protected boolean keyDown(int keycode, int time) {  
    int key = Keypad.key(keycode);
        if(key==Characters.ESCAPE){
            // do something here
            return true;
        }       
        return super.keyDown(keycode, time);
    }

To come to home screen

while(!(UiApplication.getUiApplication().getActiveScreen() instanceof HomeScreen)){
                UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
}
6
  • i need to come to blackberry home screen.how to do that? Jun 5, 2012 at 3:58
  • can u please tell where i have to write that code.i wrote in starting screen of my application back button.but its not working.it is coming again to my application homescreen only.not ocming to blackberry home screen Jun 5, 2012 at 7:09
  • @sandhya.M. Let me clear my understanding. You want to come out of the app when back button will be pressed from home screen. And, next time when you launch it should start freshly? is this your requirement?
    – Nilanchala
    Jun 5, 2012 at 7:16
  • no.i want to come out of the app from starting screen not from the home screen.and next time if i open it.it should start freshly. Jun 5, 2012 at 7:17
  • @sandhya.M. Use System.exit(0); for terminating the application when back key is pressed. protected boolean keyDown(int keycode, int time) { if(keycode == 1179648){ System.exit(0); } return super.keyDown(keycode, time); }
    – Nilanchala
    Jun 5, 2012 at 7:37
3

I got the Solution... i have written lik this.

public boolean onClose() 
    {
        int choose=Dialog.ask(Dialog.D_YES_NO, "Are you sure Want to Exit?");
        if(choose==Dialog.YES)
        {
            System.exit(0);

        }
        return true;
    }
1

Try this -

public class yourclass extends MainScreen{
      public yourclass(){

   }
   }
public boolean onClose() {
       Application.getApplication().invokeLater(new Runnable() {
            public void run() {

                             //close this screen and push your home screen  

            }
        });
        return true;
    }
1
  • i need to come to blackberry home screen.how to dothat Jun 5, 2012 at 3:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.