The project I'm working on, which uses BlackBerry SDK 6, reported a bug in which when closing an MainScreen causes the app to suddenly lose focus and stops being responsive, the message reported on the console output is foreground app ******* lost focus it has no screens
. Let me clarify than this message is shown even though a Screen on the app remains visible but somehow the app lost focus.
I haven't been able to pinpoint which are the conditions to trigger this bug, I tried to take the case where many MainScreens are opened and then I closed them by pressing the back button. I'll try to update with a much more clear output when I get to trigger this bug.
On every MainScreen the onClose
method is overriden to call a method inside our ScreenManager class, a class we created to handle the opening and closing of our MainScreens, the code for it looks like this:
public void back()
{
if(pageStack.size() - 1 == 0) {
// if only one screen is in our stack collection, show a prompt asking if user wants to close app
int choose=Dialog.ask(Dialog.D_YES_NO, ui.getRb().getString(ui.EXIT_YES_NO));
if(choose==Dialog.YES)
{
System.exit(0);
}
} else {
// in case our stack of screens has more than one screen remaining then pop it for our stack
popPageStack();
}
}
The code for popPageStack is this:
private void popPageStack() {
pageStack.removeElementAt(pageStack.size()-1);
UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
}
Is it possible that during the popScreen call is the cause for this? I'm just starting developing on BlackBerry so I don't know if a situation where a popScreen call is made and while the screen before the one poped is being rendered can a no screens on app case is possible?
EDIT
I made a test project with a menu item that when clicked, removes the only screen being displayed, after that the behaviour I described earlier happened. Indeed, I'm running out of screens somehow and the last one displayed remains "displayed" but no interaction can be made since it's been popped out already.
I'm checking my original project but I don't understand how can I trigger an onClose call when I'm just moving back using the back button. Anyway if I were to reach the last window, then a dialog should pop up asking if the app should be close.
EDIT 2
I was able to reproduce the bug two times, although after several tries. The console output I got was this:
[0.0] JVM: bklt @12347710: setTimer 30 [0.0] UIE: Focus - target lost, prev=null, input=null, app=com.yallaya.rbt.Main@9b0462e2 [0.0] UIE: Foreground app com.yallaya.rbt.Main@9b0462e2 lost focus because it has no screens. [0.0] UIE: Focus - target lost, prev=null, input=null, app=com.yallaya.rbt.Main@9b0462e2 [0.0] UIE: Foreground app com.yallaya.rbt.Main@9b0462e2 lost focus because it has no screens. [0.0] UIE: Foreground app com.yallaya.rbt.Main@9b0462e2 has no screens. This should be corrected. [0.0] UIE: Foreground app com.yallaya.rbt.Main@9b0462e2 ignoring touchscreen touch/click because it has no[0.0] target screen. [0.0] JVM: bklt @12377703: timer [0.0] JVM: bklt[1] @12377703: usrIdle 27, usrTime 30, usrAct 1 [0.0] JVM: bklt[1] @12377703: chkIdle 29, currTime 30 [0.0] JVM: bklt @12377703: setTimer 3 [0.0] JVM: bklt @12380734: timer [0.0] JVM: bklt[1] @12380734: usrIdle 30, usrTime 30, usrAct 1 [0.0] JVM: bklt[1] @12380734: chkIdle 33, currTime 30 [0.0] JVM: bklt[1] @12380734: enableBacklight 0 [0.0] JVM: bklt[1]: setTimeout 30 [0.0] JVM: bklt[1] @12386796: JBSC on=0 [0.0] JVM: bklt[1] @12386796: SC 0 [0.0] JVM: bklt[1]: setTimeout 30 [0.0] JVM: bklt[1] @12388023: JBSC on=1 [0.0] JVM: bklt[1] @12388023: SC 1 [0.0] JVM: bklt @12388023: setTimer 30
Every time I tried to interact with the screen (either touch or hardware input), the [0.0] UIE: Foreground app com.yallaya.rbt.Main@9b0462e2 has no screens. This should be corrected.
line would show.
Does this give a hint on where is my problem?