×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Feb 2014
    Posts
    8

    Display Message Box on Back Key Press Event

    Hi,

    I am trying to display a message box to exit the app on back key press before user exits the app. If i am trying to run the app without visual studio and pressing Back Key, after some 10-12 seconds automatically the app will exit without pressing any button on Message Box.

    Please let me know if there is any other way to achieve this functionality (on back key press a pop up should come for user to exit the app with Ok and Cancel button, and if user presses any button then only the app should exit).

    Need to show a message box before exiting the app as per requirement of project.


    Please help.


    Thanks & Regards,
    Jatin Juneja

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2013
    Location
    Dublin, Ireland
    Posts
    565

    Re: Display Message Box on Back Key Press Event

    Can you post some code to show how are you are doing this?

  3. #3
    Registered User
    Join Date
    Feb 2014
    Posts
    8

    Re: Display Message Box on Back Key Press Event

    Hi,

    PFB the code:-

    protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
    {
    showMessageBox();

    MessageBoxResult result = MessageBox.Show("Are you sure you want to exit ?", "Alert", MessageBoxButton.OKCancel);

    if (result == MessageBoxResult.OK)
    {
    NavigationService.RemoveBackEntry();
    }
    else
    {

    }

    // cancel the navigation
    e.Cancel = true;
    }


    If we are pressing back key the message box written on Back key press event will appear and after some 12 seconds automatically the app will exit without any input from user.

  4. #4
    Nokia Developer Champion
    Join Date
    Feb 2013
    Location
    Dublin, Ireland
    Posts
    565

    Re: Display Message Box on Back Key Press Event

    Ok, basically if you block Navigation events (OnNavigatedTo, OnNavigatedFrom, OnBackKeyPress, etc) for a long period of time (approx. 12 seconds as you suggest) then the OS watchdog will kill your app as it assumes your app has frozen or crashed.

    To get around this, you just need to change the logic of your code above...

    1. Cancel the navigation (e.Cancel = true)
    2. Display the MessageBox
    3. If Ok, Navigate Back

  5. #5
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,073

    Re: Display Message Box on Back Key Press Event

    A duplicate thread? : http://developer.nokia.com/community...event-handling or just a co-incidence (though posters are different)

  6. #6
    Registered User
    Join Date
    Feb 2014
    Posts
    8

    Re: Display Message Box on Back Key Press Event

    Hi,

    Followed below steps :-

    1. Cancel the navigation (e.Cancel = true)
    2. Display the MessageBox
    3. If Ok, Navigate Back

    but still the app is exiting without any button press on message box.

    Scenario is to show a message box on back key press "Are you sure you want to Exit?", with Ok and Cancel button.

    If user press OK, remove back stack entry to exit the app. If user press Cancel, message Box should hide and if user doesn't press anything for some time period (around 12 sec) app should stay in that particular state only without exiting it.


    Please suggest me if there is any way out for this.

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,734

    Re: Display Message Box on Back Key Press Event

    You may really want to check the other thread suggested by Vineet.
    In short: what you see is actually desired, interfering too much with the Back key will block your app from certification.

  8. #8
    Nokia Developer Champion
    Join Date
    Feb 2013
    Location
    Dublin, Ireland
    Posts
    565

    Re: Display Message Box on Back Key Press Event

    Quote Originally Posted by Jatin View Post
    Please suggest me if there is any way out for this.
    Place all the code is another method, then call that.

    Also - in WP8.1, having an exit confirmation screen will be pointless - so I'm not even sure this kind of feature is needed anymore?
    Last edited by theothernt; 2014-06-12 at 14:29.

Similar Threads

  1. Replies: 3
    Last Post: 2011-10-31, 13:37
  2. press event
    By alfah in forum Qt
    Replies: 1
    Last Post: 2011-09-08, 09:10
  3. To get key press event
    By manish88 in forum Symbian
    Replies: 16
    Last Post: 2009-03-20, 07:08
  4. editor back softkey press
    By JasonSmithMiller in forum Symbian User Interface
    Replies: 4
    Last Post: 2008-09-02, 10:40
  5. Any Key Press Event
    By marycore in forum Symbian
    Replies: 5
    Last Post: 2005-12-25, 18:56

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×