Popping multiple screens in a BlackBerry applicati

2019-08-07 05:54发布

I writing a BlackBerry app which has multiple screens that the user navigates through (like a survey). After submitting the survey the app must return to the start screen, after which, they must not be allowed to navigate back to the screens which were previously shown.

What would be the correct way to implement this?

Currently I'm calling

UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());

as many times as there were different screens. Is there perhaps a more elegant solution to get back to the start screen?

1条回答
干净又极端
2楼-- · 2019-08-07 06:10

UiApplication.getScreenCount() will always give you the number of screens, so you can just do this (from anywhere, it doesn't even have to be from any particular Screen class):

   public void popToRoot() {
      UiApplication app = UiApplication.getUiApplication();
      while (app.getScreenCount() > 1) {
         app.popScreen(app.getActiveScreen());
      }
   }
查看更多
登录 后发表回答