0

What I need is to provide an exit confirmation dialog for my mobile app.

The dialog is to appear when users taps the Back button on their phones. I know two options i.e.

  1. "Press back again if you really wish to exit" type of message.
  2. "Do you really wish to exit + Yes/No" dialog.

I am exploring the second variant.

The problem I see primarily concerns the windows store apps.

If I show it and give user time to decide than I have already cancelled the default behavior.

For windows store app it is Windows.Phone.UI.Input.HardwareButtons.BackPressed i.e. I've set the Windows.Phone.UI.Input.BackPressedEventArgs.Handled to true.

What do I do if user clicks Yes i.e. confirms his intent to exit the app?

I've read the Metro App can no longer be programmatically killed and do understand that programmatically closing the windows store app is considered "unacceptable". Does it mean that such an exit confirmation dialog is banned for windows platform?

What about Android? Is it ok there to exit the app programmatically?

Community
  • 1
  • 1
Zverev Evgeniy
  • 3,643
  • 25
  • 42

2 Answers2

0
  1. Formally Windows Store Policy does not allow such behavior:

Where applicable, pressing the back button should take the user to a previous page/dialog. If the user presses the back button on the first page of the app, then the app terminates (unless it is allowed to run in the background).

So you might be lucky to pass certification, but it is definitely not recommended behavior.

  1. For "testing purposes" there are two methods exposed in API to programmatically exit application:

Technically you can use one of these methods to force application to close after user confirmed to exit. But there is no guarantee that you will pass certification.

  1. For Android there are also guidelines. In particular the Core App Quality guide says that

App does not crash, force close, freeze, or otherwise function abnormally on any targeted device.

There are various discussion on Stack Overflow on how to correctly close Android app (example).

From my experience such apps do path certification, but Play team may choose to not promote them as they don't follow official design guidelines.

Community
  • 1
  • 1
Konstantin
  • 884
  • 6
  • 12
  • Thank you for repeating information provided in my original question i.e. the link in my question. You do not answer my questions. – Zverev Evgeniy Jun 15 '16 at 09:50
  • I updated my answer with Android case, but still not sure what exactly you are asking for. If the question is "should I use such dialog" - the answer is not, it is against guidelines. If the question is "can I close app" - the answer is yes, there are APIs for that. If the question is "will I pass certification" -- it depends, for Windows Store there are good changes that you will not due to manual tests, for Google Play from my experience with some apps - yes. – Konstantin Jun 15 '16 at 10:24
-1

You could by using the onBackPressed callback method and showing a dialog, but as Jason said, it is a bad practice on Android too.

Let me explain why.

The OS has a PackageManager which manages every apps on the device. Apps have a priority level. That's why the phone app opens when it receives a call and yours get paused (in background). If the active app with the highest priority level needs memory or if your device encounter any problems, it can destroy your activities and then close your app automatically.

Alexandre Martin
  • 1,472
  • 5
  • 14
  • 27
  • To tell the truth I do not get your explanation. I do not see any relation between your explanation and closing my app programmatically. – Zverev Evgeniy Jun 09 '16 at 19:32
  • You want the user to confirm the exit operation so you need to detect the on back button pressed and show a dialog because this button can exit the app. Are you only looking for a way to exit by yourself ? Or you want to prevent any exit action ? – Alexandre Martin Jun 09 '16 at 20:38
  • Not prevent any exit for sure. I want to prevent unwanted exit due to a misplaced tap on the back button only. This is the only case I am countering. – Zverev Evgeniy Jun 09 '16 at 21:34
  • So the callback method I told you about is what you need. Apply it on the Main / Launcher activity (in case of Android) and open a dialog, kind of popup window where you can confirm the action or not. – Alexandre Martin Jun 09 '16 at 23:35
  • I know how to implement the task myself. The question is about quite a different thing. How does this comply with the application being "nice". And reasoning for that. – Zverev Evgeniy Jun 10 '16 at 06:43
  • I answered why in my first message. The PackageManager part... This is for Android. I don't know for other platforms – Alexandre Martin Jun 10 '16 at 12:45
  • I do not understand your explanation at all. What is the relation between `bad practice` thing and `PackageManager` thing? – Zverev Evgeniy Jun 11 '16 at 00:48
  • You can't control the way the user exit the app because the Package Manager will be unable to do his job. It is a really bad practice. But it is not impossible to do. – Alexandre Martin Jun 11 '16 at 01:01
  • If the PM wants to kill your app to free memory but your app stays opened, it will cause problems. – Alexandre Martin Jun 11 '16 at 01:02
  • What problem do I create for the PackageManager if I exit my app programmatically? What in particular do you mean saying "control the way the user exit the app"? – Zverev Evgeniy Jun 11 '16 at 01:03
  • How my scenario concerns the intention of PM to kill my app? If PM wants to suspend my app I cannot prevent it. My question has nothing to do with this scenario. – Zverev Evgeniy Jun 11 '16 at 01:06
  • Any ways you are gonna use to do what you want to do, it gonna concerns the onDestroy callback method in the activity lifecycle. If the PM kills the app, it will execute the same. So the popup would open if your plan is a dialog and the app will not close – Alexandre Martin Jun 11 '16 at 01:11
  • No, no and a no again. I am only going to override the onBackPressed. Why would I need to mess with onDestroy?? – Zverev Evgeniy Jun 11 '16 at 01:17
  • I am only giving you some advices. No need to arguy or even downgrade. The reality is that you can't achieve what you want. Write a message to Google support if you are unhappy with that. It is not my fault – Alexandre Martin Jun 11 '16 at 01:24
  • The back button kills the activity so it does execute onDestroy – Alexandre Martin Jun 11 '16 at 01:24