Reputation: 5836
I was wondering how the people who develop for here BlackBerry go about managing the screens in their app. The most common practice (and the one I'm using) seems to be just to instantiate and push the new screen from the current one. The other option I've seen is using actions in the Main Application class to do the transitions. How do you guys manage?
Upvotes: 2
Views: 1837
Reputation: 365
I also just use the above method of pushing to the screen-stack however an addition to this I also pass references of screens within my stack as parameter to new screens added. If you have any public methods (which might for example update the contents of the screen etc) these can be called from other screens within your stack using this kind of reference. E.g. Screen 1
public class MyScreen1 extends MainScreen
{
private LabelField content;
public MyScreen1(){
content = new LabelField(“this is the original content”);
add(content);
}
public void UpdateScreen(String newContent){
content.setText(newContent);
}
private void PushScreen{
MyScreen2 screen = new MyScreen2( (MyScreen1)UiApplication.getUiApplication().getActiveScreen());
UiApplication.getUiApplication().pushScreen(screen);
}
}
Screen 2
public class MyScreen2 extends MainScreen
{
private MyScreen1 originalScreen
public MyScreen2(MyScreen1 originalScreen){
this.originalScreen = originalScreen
public MyScreen1 () {
LabelField content = new LabelField(“Screen1 will now be changed.”);
add(content);
UpdateScreen1();
}
private void UpdateScreen1(){
originalScreen.UpdateScreen(“This is new content”);
}
}
In this example, once MyScreen2 has been popped, the content of MyScreen1 will have changed. This is useful if you have a scenario where you display details of an object then push an edit screen for the object which would pop back to an older version of the object.
Upvotes: 1
Reputation: 1360
We have a ScreenManager
class manages the display of screens. It contains a Hashmap which has Screen name -> MainScreen pairs,public methods for adding and showing a screen.
When our application starts up all the screens required are created and added to the ScreenManager
class.
In the showScreen()
method we get the reference to the appropriate MainScreen
class. Then we use UiApplication.getUiApplication().popScreen(screen)
to hide the current screen. If the screen has already been shown we simply use popScreen()
to remove screens until we reach the screen we want. Otherwise we just pushScreen()
to move the screen to the top of the pile.
Calls to using the UiApplication
are contained within a synchronized(UiApplication.getEventLock())
block
This approach does the job for us. We can create all the screens once at the application startup so it does not need to be done over and over again during the course of the application.
Upvotes: 2