Quit Application | Confirmation Dialog

Hi,

maybe it´s a dumb question, but I don´t get further.

How to quit my Application properly?
System.exit() creates an error. I also didn´t found any function to terminate the Application, except by returning "false" within the onKey(evt).
This gave me the next challange:

In my Application, I´d like to have a confirmation dialog, when the User press the Back-Button (Ui.KEY_ESC).
Now, I have to push a View with a delegate, which returns Yes/No, in an unlimited amount of time.
The onKey(evt)-Function expects the return value true/false to quit the App. So there is, imho, no different way then waiting for the result:

function onKey(evt)
{
if(key == Ui.KEY_ESC)
{
var quitString = Ui.loadResource(Rez.Strings.quit);
var cd = new Ui.Confirmation( quitString );
Ui.pushView( cd, new QuitDelegate(), Ui.SLIDE_IMMEDIATE );
while(quit == null)
{
}
QuitApp();
return quit;
}
}

class QuitDelegate extends Ui.ConfirmationDelegate
{
function initialize()
{
quit = null;
}

function onResponse(value)
{
if( value == 1 )
{
quit = true;
}
else
{
quit = false;
}
}
}

But this gives me an Error:
Watchdog Tripped Error - Code Executed Too Long


How can I simply leave my application after an confirmation Dialog?
Until now, I found everything in the API Documentation, the SDK samples or in this forum. But that freaks me out :confused:
  • I asked this question earlier. You can see the post here. To exit your application you can either allow the top-level event delegate to return false from a back key press, or you can pop the top-level view from the view stack. For a widget, you should not pop the top-level view, so you have to return false.

    Obviously, the code above trips the watchdog because it sits in a loop. I believe the following code would do this properly...

    function onKey(evt)
    {
    if(key == Ui.KEY_ESC)
    {
    var quitString = Ui.loadResource(Rez.Strings.quit);
    var cd = new Ui.Confirmation( quitString );
    Ui.pushView( cd, new QuitDelegate(), Ui.SLIDE_IMMEDIATE );
    }

    return true;}

    class QuitDelegate extends Ui.ConfirmationDelegate
    {
    function initialize()
    {
    }

    function onResponse(value)
    {
    if( value == CONFIRM_YES )
    {
    // pop the confirmation dialog associated with this delegate
    Ui.popView(Ui.SLIDE_IMMEDIATE);

    // the system will automatically pop the top level dialog
    }

    return true;
    }
    }


    Travis
  • Former Member
    Former Member over 10 years ago
    Travis is correct.

    The comments in your confirmation response are a bit off. The system will always automatically pop the confirmation dialog. The Ui.popView added to the response event will pop the view that the dialog was pushed on top of. If that view is the base view, the app will close.
  • I asked this question earlier. You can see the post here. To exit your application you can either allow the top-level event delegate to return false from a back key press, or you can pop the top-level view from the view stack.


    Thank you very much, Travis!
    This is the point in the right direction. Now I think, I understand the concept and I can work it out! (It is working, but it´s tricky with another "Do you want to save"-Confirmation :D )
  • The system will always automatically pop the confirmation dialog. The Ui.popView added to the response event will pop the view that the dialog was pushed on top of. If that view is the base view, the app will close.


    Really? The pushView and popView functions don't operate on a stack (or pseudo-stack) of views? Now you've got me curious.

    How does the Ui.popView call in the confirmation know what view to remove? The call itself doesn't take a reference to the object to remove, so it needs to come from somewhere.

    I don't have an environment setup here at work, but what would happen if the onResponse implementation was changed to do this...

    function onResponse(value)
    {
    if( value == CONFIRM_YES )
    {
    var cd = new Ui.Confirmation( "Test" );
    Ui.pushView( cd, new QuitDelegate(), Ui.SLIDE_IMMEDIATE );
    }

    return true;
    }


    If what you are saying is correct, then the a Yes response would show a second confirmation dialog labelled "Test" (the quit dialog was popped out from under the pushed confirmation), otherwise, they will be right back at the "Quit" dialog (returning from onResponse popped the freshly pushed confirmation), right?
  • Former Member
    Former Member over 10 years ago
    Things do get a bit hard to visualize when you start manipulating views in the confirmation view response, but the confirmation will always pop itself and not another view.

    It is probably best conceptually to think of things as if the confirmation view has already been popped from the view stack when the onResponse method is called.

    That isn't technically true right now, but I would eventually like it to be when I have some time to improve our handling of view control. What is actually happening in the system is just strange, but the end result is consistent with that assumption.
  • Thank the both of you very, very much!
    I got it working right now, exactly as I wanted :cool: