0

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?

Patrick
  • 1,717
  • 7
  • 21
  • 28
Uriel Arvizu
  • 1,876
  • 6
  • 37
  • 97
  • Similar question asked on BB forum here: http://supportforums.blackberry.com/t5/Java-Development/App-freezes-when-closing-a-MainScreen-loses-focus-and-says-it/td-p/2918548 – Peter Strange Jun 28 '14 at 11:06

1 Answers1

0

@Uriel Arvizu

Since we have to have at least one screen present on display stack we call it parent screen by convention (not a concept) if we are poping this screen from display stack and trying to run anything after that it will show device hang or screen lag...

so when you are implementing popscreen method, i suggest you implement it on your screen class( which is extending mainscreen ) and provide "this" to it which is current instance of screen.. and you can call the method to pop a screen on back button click like :

ButtonField buttonBack = new ButtonField(new StringProvider("Back"));

buttonBack.setChangeListener(new FieldChangeListener() {
    public void fieldChanged(Field field, int context) {
       closeThisScreen();
    }
});

method to close this screen in same class

void closeThisScreen() {
    UiApplication.getUiApplication().popScreen(this);
}

When it is displaying home screen and user press back button display a message and then close the application implement this on home screen

public boolean onClose()
        {
            int response = Dialog.ask(Dialog.D_YES_NO,"Are you sure you want exit?");
            if (response == -1)
            {
                return false;
            }
            else
            {
                System.exit(0);
                return true;
            }
        }
user2408578
  • 464
  • 1
  • 4
  • 13
  • I've been testing and I haven't been able to find a specific pattern to reproduce the bug, it's so erratic, sometimes it happens on one screen and then on a different, it doesn't happen always. Could it be I'm running out of memory? Check the new edit on my question, I added the message I get on the output console. – Uriel Arvizu Jul 01 '14 at 23:15