Using Activities as Dialogs

Dialogs offer a simple and lightweight technique for displaying screens, but there will still be times when you need more control over the content and life cycle of your dialog box.

The solution is to implement it as a full Activity. By creating an Activity you lose the lightweight nature of the Dialog class, but you gain the ability to implement any screen you want and full access to the Activity life-cycle event handlers.

The easiest way to make an Activity look like a dialog is to apply the android:style/Theme.Dialog theme when you add it to your manifest, as shown in the following XML snippet:

<activity android:name="MyDialogActivity"

android:theme="@android:style/Theme.Dialog">

</activity>

This will cause your Activity to behave as a Dialog, floating on top of, and partially obscuring, the Activity beneath it.

Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide


Post a comment