Lock orientation on Storm
I need to lock my application in portrait mode on a Storm(and Strom 2) device.
I use Ui.getUiEngineInstance().setAcceptableDirections(Display.DIRECTION_PORTRAIT);
for this.
Here is the problem:
The screen direction only changes once the device is rotated to a direction supported by the provided direction parameter.
(source)
If the user has the device in landscape m开发者_如何学Goode and opens the application, the application will open in landscape and will only lock to portrait mode when/if the user rotates the device to portrait mode.
Is there any way to force the application in portrait mode even in the case I described above?
I have made a static method that I call from my application's main()
method.
See the full code in my answer to this question: How to fix alignment for vertical and portrait screen in BlackBerry?
It can be solved by creating a custom class which extends MainScreen class which accepts the nextScreenObject as an argument in the constructor
and then by using
UiApplication.getUiApplication.pushModalScreen(nextScreenObj); //This would lock the screen
So whenever you push any screen create an object of this custom class and send the screen object as an argument to this constructor
Eg: Let NewCustomClass be your custom class which extends MainScreen then while pushing a new screen you can
NextScreen nextScreenObj = new NextScreen(..args..); NewCustomClass pushObj = new NewCustomClass(nextScreenObj);
Let me know if the problem is solved.
精彩评论