Over a million developers have joined DZone.

Risks and Reasons for the Use of Exit Guards

· Mobile Zone

Visually compose APIs with easy-to-use tooling. Learn how IBM API Connect provides near-universal access to data and services both on-premises and in the cloud, brought to you in partnership with IBM.

I was recently asked if there's a way to show a message box when exiting a Windows Phone app by the home (Windows) button. The thoroughness of my response was remarked upon, so I thought I'd share it here to let everyone know my thoughts.

As far as I know, the only guaranteed way of forcing a (confirmation?) message box when leaving an app, via the public SDK, is by overriding the back button. There may, of course, be undocumented or private APIs that exist for this, though. Obviously, overriding the back button behavior will only take effect when leaving the app by pressing the back button.

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 leaves 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 from EVER leaving the app, which would be the equivalent of being able to override the other hardware buttons, or stop someone launching another app from the system UI (for example, Toasts, notifications or answering incoming calls). There may be a few cases, such as LOB apps, where this may be desirable, but it doesn't make sense in terms of a general-purpose, consumer focused, mobile operating system.

Typically, apps try to 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, so it assumes the users won't be either. Coding for this just reinforces uncertainty in the system and an inconsistent experience across apps.
  2. The navigation model within the app is confusing and users aren't always clear where they are in the app, so they don't realize they're exiting by pressing back. This is an IA issue and 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, so it's 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.
The other reason I've seen for wanting to confirm application exit 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 he/she wants it restored when the user returns to the app. The nature of the data, the app and how the user returns to it can also have an impact on what is most appropriate here.

Sorry I can't be more explicit, but I hope this helps.

The Mobile Zone is brought to you in partnership with Strongloop and IBM.  Visually compose APIs with easy-to-use tooling. Learn how IBM API Connect provides near-universal access to data and services both on-premises and in the cloud.


Published at DZone with permission of Matt Lacey, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}