Avoid Custom Dialogs for Non-Trivial Interactions
Monday, January 09, 2012, Modified: Monday, January 09, 2012 Refs

It is tempting to use the Dialog class with a custom layout to build a form for a user to enter some data. By enter data, I mean to do the sorts of things that you might use a substantial dialog box for in a desktop application. There are certainly plenty of resources out there if you want to try that approach.

Don't do it though, no matter how natural it might seem to be to use the Dialog class to implement a dialog box. The main reason that doing so is a bad idea is that Dialog doesn't participate in the Android application lifecycle. While an Android application must be written to be able to recover from having its process killed at any moment, a Dialog doesn't get the same notification to save its state that an Activity does just before the process goes down. So, if the system does decide to kill your app when a user is halfway through entering data into a Dialog (perhaps having switched to a browser to look something up and having gotten distracted), they won't be happy to find that everything that they have entered has been lost when they switch back.

The solution for these sorts of interactions is to use an Activity with the dialog theme:

Try Buffer, a smarter way to share links and pictures by spreading your tweets and posts out over time. Sign up from this link and we both get extra features.

Buffer
Home :: Items