Mastering Android Dialogs: Don’t follow official Google Guides
--
This article is part of a multi-series on Mastering Android Dialogs
- Don’t follow official Google Guides
- Using Coroutines to show and get results from Dialogs easily
COMING SOON
Intro
Callbacks, listeners, onActivityResults — these are spread all over Android APIs, and frankly speaking, it drives me crazy. Every time you want to ask for permission, take a picture, choose a file, or even show a simple dialog you have to deal with them. After some time I feel more like playing ping-pong in Android than actually writing readable, maintainable, and, what’s very important, REUSABLE code.
Do we have to use them? Is there a better way? Of course, there are lots of better ways and countless solutions to the same problem — as usual in Android. This article explains why Google Guides for Dialogs are bad and what risks you and your apps may face if you follow them.
What is currently recommended by Google?
Let’s look into the official documentation as of November 2022 and check out what Google recommends when dealing with dialogs. The most common places to find information about it are the guides below.
- Dialogs UI Guide https://developer.android.com/develop/ui/views/components/dialogs
- Displaying dialogs with DialogFragment Guide https://developer.android.com/guide/fragments/dialogs
- Create destinations https://developer.android.com/guide/navigation/navigation-create-destinations
- Interact programmatically with the Navigation component https://developer.android.com/guide/navigation/navigation-programmatic
The guides are not very long, to be honest. They are very deficient. I could imagine someone who’s just started learning Android and wants to get into Dialogs, but he only finds a few simple examples, not fitting into most real-world apps. Unfortunately, that’s the case for most guides and samples.
Let’s go over these guides and recommendations 👇