×
Namespaces

Variants
Actions
(Difference between revisions)

Confirming that the user wants to leave the app

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Fix metadata)
hamishwillee (Talk | contribs)
m (Hamishwillee - Subedit for wiki style)
Line 1: Line 1:
[[Category:Windows Phone 8]][[Category:Windows Phone]][[Category:XAML]][[Category:Tutorial]][[Category:UI on Windows Phone]]
+
[[Category:UI on Windows Phone]][[Category:Application Framework on Windows Phone]][[Category:XAML]][[Category:Windows Phone 8]]
{{Abstract|This article explains discusses prompting the user before they leave an app. }}  
+
{{Abstract|This article explains discusses why it is a "bad idea" to prompt users to confirm whether to exit an app. }}  
 
+
 
{{ArticleMetaData <!-- v1.3 -->
 
{{ArticleMetaData <!-- v1.3 -->
 
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
Line 23: Line 22:
  
 
== Introduction ==
 
== Introduction ==
It's easy to ask a user to confirm that they want to leave an app (or page) by overriding the `OnBackKeyPress` method on a page.
 
See:
 
  
    protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
+
Windows Phone does not support the user paradigm of asking users to confirm that they want to close an app on exit. Instead the back arrow is expected to close the app in all cases. If necessary the app should automatically save all data and restore it if needed.
    {
+
        var result = MessageBox.Show("Are you sure you want to exit the app?", "Please confirm", MessageBoxButton.OKCancel);
+
   
+
        e.Cancel = result != MessageBoxResult.OK;
+
   
+
        base.OnBackKeyPress(e);
+
    }
+
  
But what if you want to add this confirmation when the user leaves the app in ways other than pressing the back button?
+
Developers from other platforms may question this design approach. Usually this is due to a lack of understanding of the application framework and UI design.
  
== Summary ==
+
This article explains why forcing confirmation on exit is not required, and why in fact it is not possible to "fully implement".
The short answer is that it's not possible to prompt the user when they leave an app in other ways and it certainly isn't possible to stop them leaving.
+
Let's look at why.
+
  
== Explanation ==  
+
== Why try to save user data on exit ==
Leaving the app in any other way will cause the application level events to be triggered and these cannot block indefinitely (and actually only have a few seconds to run) as to do so would risk compromising the OS.
+
Imagine for instance if you could throw up a message box when someone left an app for any reason (and cancel the navigation dependent upon the result). This would enable the creation of an app that could prevent the user EVER leaving the app. This would be the equivalent of being able to override the other hardware buttons or stop someone launching another app from system UI (E.g. Toasts, notifications or answering incoming calls)
+
There may be a few cases such as Line Of Business apps where this may be desirable but it doesn’t make sense in terms of a general purpose, consumer focused, mobile operating system-like Windows Phone.
+
  
 
Typically apps try and force a confirmation on exit to avoid accidentally closing the app. There are a few motivations behind this.  
 
Typically apps try and force a confirmation on exit to avoid accidentally closing the app. There are a few motivations behind this.  
# The company behind the app isn’t familiar with the OS and closing apps via the back button and so they assume the users won’t be either. – Coding for this just reinforces uncertainty in the system and an inconsistent experience across apps.
+
# The company behind the app isn't familiar with the OS and closing apps via the back button and so they assume the users won’t be either. This is not a good justification because it produces an inconsistent experience across apps in the platform.
# The navigation model within the app is confusing and users aren’t always clear where they are in the app and so don’t realize they’re exiting by pressing back. This is an Information Architecture issue and should be solved with better UX design.
+
# The navigation model within the app is confusing and users aren't always clear where they are in the app - as a result they don't realize that pressing the back arrow will exit the app. This should be solved with better UX design.
# Users often close accidentally and have to relaunch the app, which is very slow. Confirming closing is faster than restarting the app and so seen as beneficial. – The better solution here would be to improve startup/launch time. This would also help all users of the app and not just those who close the app accidentally.
+
# Users often close accidentally and have to relaunch the app, which is very slow. Confirming closing is faster than restarting the app and so seen as beneficial. A better solution is to improve startup/launch time. This would also help all users of the app and not just those who close the app accidentally.
  
  
The other reason commonly seen for wanting to confirm application exit is if there is entered but unsaved data. In this scenario it is normally better to automatically save it (login credentials being the usual exception) and then restore it, or ask the user if they want it restored when the user returns to the app. The nature of the data, the app and how they return to it can also have an impact on what is most appropriate here.
+
The other main reason for wanting to confirm application exit is to store unsaved data. In Windows Phone it is normally better to automatically save data (login credentials being the usual exception) and then restore it (or ask the user if they want it restored when the user returns to the app). The nature of the data, the app and how they return to it can also have an impact on what is most appropriate.
  
 +
== But I really want to ask them for confirmation ==
  
 +
This cannot be done "completely", and for the reasons in the previous section it is better to work with the platform than against it.
  
== References ==
+
It's easy to ask a user to confirm that they want to leave an app (or page) by overriding the {{Icode|OnBackKeyPress}} method on a page:
[http://Confirming%20that%20the%20user%20wants%20to%20leave%20the%20app http://developer.nokia.com/Blogs/Community/2013/09/18/confirming-that-the-user-wants-to-leave-the-app/]
+
  
''Remove Category:Draft when the page is complete or near complete''
+
<code csharp>
 +
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
 +
{
 +
    var result = MessageBox.Show("Are you sure you want to exit the app?", "Please confirm", MessageBoxButton.OKCancel); 
 +
    e.Cancel = result != MessageBoxResult.OK;
 +
    base.OnBackKeyPress(e);
 +
}
 +
</code>
 +
 
 +
However this will not prevent the user from leaving the app in other ways, for example by selecting the "Windows Start" button. While this triggers application level events these cannot block indefinitely (and actually only have a few seconds to run). As a result you cannot ask for user  confirmation and block.
 +
 
 +
This is good platform design. If an app could throw up a message box when someone left an app for any reason (and cancel the navigation dependent upon the result) this would enable the creation of an app that could prevent the user EVER leaving the app. This would be the equivalent of being able to override the other hardware buttons or stop someone launching another app from system UI (E.g. Toasts, notifications or answering incoming calls).
 +
 
 +
== References ==
 +
* [http://developer.nokia.com/Blogs/Community/2013/09/18/confirming-that-the-user-wants-to-leave-the-app/ Confirming that the user wants to leave the app] (Nokia Developer blogs)
  
 
{{VersionHint}}
 
{{VersionHint}}

Revision as of 09:21, 20 September 2013

This article explains discusses why it is a "bad idea" to prompt users to confirm whether to exit an app.

WP Metro Icon UI.png
SignpostIcon XAML 40.png
WP Metro Icon WP8.png
SignpostIcon WP7 70px.png
Article Metadata
Tested with
SDK: Windows Phone 7.1, Windows Phone 8.0 -->
CompatibilityArticle
Created: mrlacey (19 Sep 2013)
Last edited: hamishwillee (20 Sep 2013)

Contents

Introduction

Windows Phone does not support the user paradigm of asking users to confirm that they want to close an app on exit. Instead the back arrow is expected to close the app in all cases. If necessary the app should automatically save all data and restore it if needed.

Developers from other platforms may question this design approach. Usually this is due to a lack of understanding of the application framework and UI design.

This article explains why forcing confirmation on exit is not required, and why in fact it is not possible to "fully implement".

Why try to save user data on exit

Typically apps try and force a confirmation on exit to avoid accidentally closing the app. There are a few motivations behind this.

  1. The company behind the app isn't familiar with the OS and closing apps via the back button and so they assume the users won’t be either. This is not a good justification because it produces an inconsistent experience across apps in the platform.
  2. The navigation model within the app is confusing and users aren't always clear where they are in the app - as a result they don't realize that pressing the back arrow will exit the app. This should be solved with better UX design.
  3. Users often close accidentally and have to relaunch the app, which is very slow. Confirming closing is faster than restarting the app and so seen as beneficial. A better solution is to improve startup/launch time. This would also help all users of the app and not just those who close the app accidentally.


The other main reason for wanting to confirm application exit is to store unsaved data. In Windows Phone it is normally better to automatically save data (login credentials being the usual exception) and then restore it (or ask the user if they want it restored when the user returns to the app). The nature of the data, the app and how they return to it can also have an impact on what is most appropriate.

But I really want to ask them for confirmation

This cannot be done "completely", and for the reasons in the previous section it is better to work with the platform than against it.

It's easy to ask a user to confirm that they want to leave an app (or page) by overriding the OnBackKeyPress method on a page:

protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
var result = MessageBox.Show("Are you sure you want to exit the app?", "Please confirm", MessageBoxButton.OKCancel);
e.Cancel = result != MessageBoxResult.OK;
base.OnBackKeyPress(e);
}

However this will not prevent the user from leaving the app in other ways, for example by selecting the "Windows Start" button. While this triggers application level events these cannot block indefinitely (and actually only have a few seconds to run). As a result you cannot ask for user confirmation and block.

This is good platform design. If an app could throw up a message box when someone left an app for any reason (and cancel the navigation dependent upon the result) this would enable the creation of an app that could prevent the user EVER leaving the app. This would be the equivalent of being able to override the other hardware buttons or stop someone launching another app from system UI (E.g. Toasts, notifications or answering incoming calls).

References

Version Hint

Windows Phone: [[Category:Windows Phone]]
[[Category:Windows Phone 7.5]]
[[Category:Windows Phone 8]]

Nokia Asha: [[Category:Nokia Asha]]
[[Category:Nokia Asha Platform 1.0]]

Series 40: [[Category:Series 40]]
[[Category:Series 40 1st Edition]] [[Category:Series 40 2nd Edition]]
[[Category:Series 40 3rd Edition (initial release)]] [[Category:Series 40 3rd Edition FP1]] [[Category:Series 40 3rd Edition FP2]]
[[Category:Series 40 5th Edition (initial release)]] [[Category:Series 40 5th Edition FP1]]
[[Category:Series 40 6th Edition (initial release)]] [[Category:Series 40 6th Edition FP1]] [[Category:Series 40 Developer Platform 1.0]] [[Category:Series 40 Developer Platform 1.1]] [[Category:Series 40 Developer Platform 2.0]]

Symbian: [[Category:Symbian]]
[[Category:S60 1st Edition]] [[Category:S60 2nd Edition (initial release)]] [[Category:S60 2nd Edition FP1]] [[Category:S60 2nd Edition FP2]] [[Category:S60 2nd Edition FP3]]
[[Category:S60 3rd Edition (initial release)]] [[Category:S60 3rd Edition FP1]] [[Category:S60 3rd Edition FP2]]
[[Category:S60 5th Edition]]
[[Category:Symbian^3]] [[Category:Symbian Anna]] [[Category:Nokia Belle]]

215 page views in the last 30 days.
×