09-24-2009 06:06 AM
09-24-2009 06:31 AM
Hi Simon,
I'm using Bold 9000 simulator
When I use Ui.getUiEngine().getActiveScreen() in UiApplication, it returns the current screen of my own application, even if I go background:
public class UseActiveScr extends UiApplication { public UseActiveScr() { pushScreen(new MainScreen()); requestBackground(); Screen screen = Ui.getUiEngine().getActiveScreen(); Menu menu = screen.getMenu(0); for (int i = 0, cnt = menu.getSize(); i < cnt; i++) System.out.println(menu.getItem(i).toString()); } public static void main(String[] args) { UseActiveScr app = new UseActiveScr(); app.enterEventDispatcher(); } }
console output:
Starting SOUseActiveScr
Started SOUseActiveScr(163)
Foreground SOUseActiveScr(163)
FocusHistory: Focus lost; App Home Screen; Component net.rim.device.apps.internal.ribbon.launcher.RibbonIconField
Close
If I use Ui.getUiEngine().getActiveScreen() in Application (background app) it will simply throw null ref exception:
public class UseActiveScr extends Application { public UseActiveScr() { Screen screen = Ui.getUiEngine().getActiveScreen(); Menu menu = screen.getMenu(0); for (int i = 0, cnt = menu.getSize(); i < cnt; i++) System.out.println(menu.getItem(i).toString()); } public static void main(String[] args) { UseActiveScr app = new UseActiveScr(); app.enterEventDispatcher(); } }
So how should use Ui.getUiEngine().getActiveScreen() to get phone app screen?
09-24-2009 06:47 AM
09-24-2009 07:36 AM
09-24-2009 07:45 AM
System.exit, on BlackBerry, terminates the process in which it is invoked. If a listener has a hard reference to the Application that was running inside that process, nothing bad happens (the application process still terminates). The listener can always query the Application instance to see whether it's still running (Application.isAlive()). The listener, every time it is invoked, could check whether the Application instance is still running. If not, the listener can deregister itself thus making the Application instance no longer reachable via hard references (becoming a candidate for garbage collection). The catch here is that, until the listener is invoked, the Application instance will remain reachable and won't be garbage-collected (and that instance usually hard-references lots of other stuff).
A slightly improved solution would be for the listener to keep a weak reference to the Application instance. Thus, even without invoking the listener the Application instance could be garbage-collected after the application it represents terminates.
09-24-2009 08:02 AM
09-24-2009 08:07 AM
I suspect (don't have access to a JDE or a BlackBerry at the moment) the listeners you see (using a Debugger I presume) inside the native applications are wrappers around the actual listeners that are provided by third-party applications. What's puzzling is why would they have a reference to the third-party Applications at all if the listeners' callback code is invoked inside the native application process (e.g., Phone)? May the reference is there for future use...
What I meant with auto-unregistration, is that a listener registered from a third-party app (i.e., our code which we have control over) can keep its own (weak) reference to the Application that registered it and then self-unregister once the application is no longer running or once the weak reference is no longer there.
09-24-2009 08:12 AM
09-26-2009 08:35 AM