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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:45:32+00:00 2026-05-21T18:45:32+00:00

I have an AlertDialog that needs to be used in several Activities. How can

  • 0

I have an AlertDialog that needs to be used in several Activities. How can I accomplish this with its own Class? Thank-you for your help!~!

I tried the following and acces it in an Activity w:

Alerts.sdCardMissing();

The class I ‘tried’ to create:

public class Alerts {

public static void sdCardMissing() {
    AlertDialog alertDialog = new AlertDialog.Builder(null).create();
    alertDialog.setTitle("External Storage State");
    alertDialog
            .setMessage("Your SD-Card is not mounted!  If the device is plugged into a computer via the USB, please disconect the device.");
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // this.finish();
        }
    });
    // alertDialog.setIcon(R.drawable.icon);
    alertDialog.show();
}

}

  • 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-21T18:45:33+00:00Added an answer on May 21, 2026 at 6:45 pm

    Try…

    public class Alerts {
        public static void sdCardMissing(Context context) {
            // Pass context to AlertDialog.Builder
            AlertDialog alertDialog = new AlertDialog.Builder(context).create();
            ...
        }
    }
    

    Then call it from the Activity with…

    // Pass the Activity context as 'this'
    Alerts.sdCardMissing(this);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can someone help me with this? I have an AlertDialog box and its working
I have following code for alertdialog: AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this); helpBuilder.setTitle(Options); helpBuilder.setMessage(Choose Your
So i have this activity : public class settings_dock extends Activity { AlertDialog alert;
I have button that a user selects and I pop up a AlertDialog to
I have a Login dialog that can create an alert dialog when the user
My application starts from an Main activity and this main activity has its own
I have created a dialog that shows a multi-choice list of items that can
I have an app that needs to scan a barcode to get a code
I've got this dialog (I'm simplifying my use case): class EditShoppingListDialog extends AlertDialog {
I have a AlertDialog that uses a Custom Layout. In the OnClick Event I

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.