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?

有帮助吗?

解决方案

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());
      }
   }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top