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 6683351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:48:42+00:00 2026-05-26T04:48:42+00:00

I want to create a single class which I can call when I need

  • 0

I want to create a single class which I can call when I need to show an AlertDialog with the parameters and son on I want.

The problem is I dont know if that class have to be an Activity… the alertDialog needs an context, but I can send the current one, because what I want is to show the alert on the actual activity (not to create a new one, I want to show the alert on the actual screen). But I cant get it. I get errors sending the context of the actual activity…

Only I get working it when I create that class like an Activity, but with that, the alertDialog appears alone without the actual screen behind.

What Can I do? I don’t know if I understand the contexts…

Thanks

  • 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-05-26T04:48:43+00:00Added an answer on May 26, 2026 at 4:48 am

    Your class does not need to extend anything to produce a dialog. You can try this way to produce a static method that creates a dialog for you.
    Make sure when you call your method you use THIS and not getApplicationContext()

    MyDialogClass.getDialog(this); //good! 
    MyDialogClass.getDialog(getApplicationContext()); //results in error
    

    That is likely the cause of your error

    Example class:

    public class MyDialogClass
    {
     public static AlertDialog getDialog(Context context)
        {
            Builder builder = new Builder(context);
            builder.setTitle("Title").setMessage("Msg").setCancelable(false)
                    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id)
                        {
    
    
                        }
                    }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id)
                        {
    
                        }
                    });
            return builder.create();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I dont know which is the best practice when we want to create a
In ruby, I want to create a method on a class which will save
I want to create multiple versions of print-friendly pages from a single page. I
I want to create a client side mail creator web page. I know the
I want to create my own expandable/collapsable tree-like UserControl, which nodes are the Border
I'm trying to single source a form page which can be in edit mode
I have a DB helper class which extends SQLiteOpenHelper and in onCreate, I want
I want a small (< 30MB) standalone Windows executable (a single file) that creates
I want create a drop shadow around the canvas component in flex. Technically speaking
I want create a excel with Apache POI in java and I must insert

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.