Managed DialogsActivity

The ManagedDialogsActivity class acts as a base class for your activities that support managed dialogs. It keeps a single instance of DialogRegistry to keep track of the managed dialogs identified by the IDialogProtocol interface. It allows the derived activities to register their dialogs through the registerDialogs() function. As shown in Figure 5-6, it is also responsible for transferring the create and prepare semantics to the respective dialog instance by locating that dialog instance in the dialog registry. Finally, it provides the callback method dialogFinished for each dialog in the dialog registry (see Listing 5-31).

Listing 5-31. The ManagedDialogsActivity Class public class ManagedDialogsActivity extends Activity implements IDialogFinishedCallBack

//A registry for managed dialogs private DialogRegistry dr = new DialogRegistry();

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedlnstanceState); this.registerDialogs();

protected void registerDialogs() {

// does nothing

// have the derived classes override this method // to register their dialogs // example:

// registerDialog(this.DIALOG_ALERT_ID_3, gmad);

public void registerDialog(IDialogProtocol dialog) {


^Override protected Dialog onCreateDialog(int id) { return this.dr.create(id);

^Override protected void onPrepareDialog(int id, Dialog dialog) { this.dr.prepare(dialog, id);

public void dialogFinished(ManagedActivityDialog dialog, int buttonId) {

//nothing to do

//have derived classes override this

0 0

Post a comment