Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: When to use Dialog vs. Activity

Tags:

android

When is it preferable to use a Dialog box as opposed to an Activity in Android? From my understanding, anything you can do with a Dialog box you can also accomplish with an Activity. Are there any tasks that can only be accomplished by an Activity or a Dialog?

like image 469
zer0stimulus Avatar asked Jul 23 '10 01:07

zer0stimulus


People also ask

Is a dialog an activity android?

In this tutorial we would be learning how to create an activity dialog in android. As shown in the below figure, an Activity Dialog is like an Activity floating over another Activity(parent activity). You can't access the parent activity until the dialog activity is destroyed.

What is the use of dialog in android?

A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed.

What's the difference between dialog and AlertDialog in android?

AlertDialog is a lightweight version of a Dialog. This is supposed to deal with INFORMATIVE matters only, That's the reason why complex interactions with the user are limited. Dialog on the other hand is able to do even more complex things .

When a dialog is displayed on top of your activity?

when a dialog is shown or it's window comes visible on top of an existing activity, then it overrides partial the activity window so existing activity will move to partially invisible state and you will get call to onPause() from ActivityThread. but to be sure we also need to consider here a one think...


3 Answers

Is what you're doing worth a new Activity? Do you need to be able to start it through an intent? Do you really need to create a new Java class for it?

If it's a straightforward dialog that displays a text and has simple hooks for positive/negative/dismissal functions, definitely use a dialog.

If you have something complex, you may want to go for a full-blown activity.

like image 172
EboMike Avatar answered Oct 19 '22 18:10

EboMike


Well why exactly would you want to start a new activity just to ask the user "Are you sure? Y/N"? Dialogs generally run on top of the activity, and are usually smaller activities or notifications for the user. They also usually have something to do with the process of the app running. It helps make things simpler to open a dialog to prompt the user on top of your activity, than to start a new activity atop your current activity.

like image 28
James Avatar answered Oct 19 '22 17:10

James


I went for Activities when I needed an user interaction that needs backstack, navigation, lifecycle and callable features.. else with dialogs. Being from the WebApp world I ask whether I would have needed a new server page or a pop window for an interaction and the decision in Andoird world becomes easier!

If newServer page then mostly Activity

elseIf popUpWindow then dialog

like image 1
Vivu Avatar answered Oct 19 '22 17:10

Vivu