I need to know with event fire when the app is closed or exit from the the home and multitasking buttons in android. I need to show the confirmation alert to user.Can any body help me to sort out the issue.Thanks
Asked
Active
Viewed 313 times
1
-
2That's anti-pattern for mobiles devices. User should be able to exit app instantly – Anton Malyshev Feb 22 '18 at 17:17
-
A confirmation dialog to close your app is a very bad idea. How are your users going to react when your app interferes with them switching to another app? (Hint: don't expect high app store ratings.) How are you going to handle things like incoming phone calls? – Ted Hopp Feb 22 '18 at 17:30
-
Hi @TedHopp am working this for an organization they need this they don't want any rating – Muhammad Ahsan majeed Feb 22 '18 at 17:52
-
Whoever developed this requirement should read some of the analyses on why exit dialogs should be avoided. A good starting place is this post by Alex Lockwood: ["Exit Application?" Dialogs Are Evil, Don't Use Them!](https://www.androiddesignpatterns.com/2012/08/exit-application-dialogs-are-evil-dont.html). Also read the [Google design guidelines on confirming and acknowledging](https://developer.android.com/design/patterns/confirming-acknowledging.html). – Ted Hopp Feb 22 '18 at 18:17
1 Answers
0
You should be looking at the lifecycle of an Android Activity, instead of events. More specifically, the onDestroy() method is called when the app is destroyed. You can show a confirmation dialog in your onDestroy or onStop() method.
However, I do not think this is a good design. The app must be able to exit smoothly without confirmations.
Additionally, you can use isFinishing() within onDestroy to differentiate b/w when app is really getting killed, and when the app is going in background / screen is rotated,
Reference: How to distinguish between orientation change and leaving application android
-
`onStop()` and `onDestroy()` are also called in other situations, such as when the activity is being re-created because the device was rotated. Popping up a confirmation dialog in those cases is a good way to antagonize users (and possibly crash the app, if the dialog isn't handled right). Also, `onDestroy()` isn't called just because the device goes to the home screen. – Ted Hopp Feb 22 '18 at 17:28
-
Umm, that's exactly what I said "However, I do not think this is a good design. The app must be able to exit smoothly without confirmations." – Feb 22 '18 at 17:30
-
That part I agree with. I was objecting the the last sentence of your first paragraph. – Ted Hopp Feb 22 '18 at 17:32
-
yes I knew this is not a good design but this is the requirement of the user – Muhammad Ahsan majeed Feb 22 '18 at 17:55
-