Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8564309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:10:12+00:00 2026-06-11T17:10:12+00:00

One of the struggles I have as android development newbie is that my classes

  • 0

One of the struggles I have as android development newbie is that my classes have the tendency to get quite extensive with all the inner classes etc for gui listener and so on. So I came up with one solution to decompose my classes which I would like to hear some feedback form the android experts around.

To put it into an example. I dont want to define all the dialogs a particular Activity has within the same class (there is a series of Dialogs taking place in that activity)
So I implemented a DialogManager class to define and hold all the potential Dialogs, hand over a handler instance from the Activity to this DialogManager and use it to inform the Activity about what gui events have happened.

Here a snippet of this DialogManager class, mHandler is the handler which calls back to the Activity

mDownloadDialog = new ProgressDialog(mContext);

mDownloadDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Cancel",
                new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {                      

                        mDownloadDialog.dismiss();

                        Message message = mHandler.obtainMessage();
                        message.arg1 = DOWNLOAD_DIALOG;
                        message.arg2 = AlertDialog.BUTTON_NEGATIVE;
                        message.sendToTarget();
                    }
                });

So this works and I am happy with the more organized source code now but I wonder if the Handler class is the proper way to do this or if this is a bit of an overkill and there are some better ways to achieve the same result which are recommended.

EDIT:
As pointed out by boulder

handler messages aren’t executed immediately

So with this in mind using Handler is not the proper way to go.

Next idea would be as simple as defining in the given example an Interface

public interface DialogEventReceiverInterface { 
public void dialogEvent(int dialog,int button);
}

implementing that interface in the Activity, hand the activity over to the DialogManager and call dialogEvent in the case an event takes place. Pretty straight forward it seems to me now …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:10:13+00:00Added an answer on June 11, 2026 at 5:10 pm

    I appreciate that you’re not necessarily specifically asking about tidying up the clutter associated with Dialogs, but rather the Dialog code you show is just an illustration of a wider problem I think you’re asking for a design pattern to solve.

    However, focusing on your specific example of Dialogs, the Android APIs now already provide a much cleaner solution for this in the form of Fragments and specifically DialogFragment. Using the Fragment classes is a much cleaner way of doing things because you generally define your DialogFragments in separate class files. The Android API documentation contains very good guidelines about how to handle communication between the DialogFragments and parent Activity.

    Before I switched to using Fragments for everything, I too ended up with lots of Dialogs being created within Activity classes and I tried various design patterns with dialog managers, etc. However, the Fragment approach is so much cleaner in my opinion.

    Compatibility with earlier Android versions is no problem because you can use the V4 support package.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an android app that is getting fairly large and complex now, and
On one hand I have coded a function in Scala that reads Excel Files.
We Really need some help on this one: We've Struggled with all the Apple
one question about PHP Development. I am building up some Form Fields for Calculations.
One of the neat characteristics of UTF-8 is that if you compare two strings
One can say a type parameter T must have a specific supertype S_1: class
One car must have one owner, and an owner can have many cars.
I have app with two sites, one where design is done and other which
We have a GAE application that notifies users of sports goal changes and we
I have struggled with this for a long time, and I did get a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.