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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:41:36+00:00 2026-05-27T11:41:36+00:00

the AlertDialog.Builder constructor takes a Context as its parameter : AlertDialog.Builder (Context context) ,

  • 0

the AlertDialog.Builder constructor takes a Context as its parameter :

AlertDialog.Builder (Context context),

and i found an example where the parameter is not only this but :

new AlertDialog.Builder(MyClassName.this);

Why that?

Also, i’ve already seen this thing with Activity, where this time we add .class to the name of the activity we try to reach. Can you please tell me the meaning of those 2 keywords?

Thanks a lot

  • 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-27T11:41:37+00:00Added an answer on May 27, 2026 at 11:41 am

    The class Activity is a sub-class of Context so you can use it as parameter in your example.
    Now if for instance, you are inside an onClick method (i.e. button) or inside an inner class or an asynctask, using ‘this’ would not refer the activity itself so you need to use YourActivity.this.

    Instead when you see ClassName.class it usually is because you need to specify wich activity, service or whatever you want to start, in that case the parameter type is Class.
    For example if you want to start an activity, you use:

    Intent intent = new Intent(this or ActivityName.this, AnotherActivityName.class);
    

    For example:

    public class MyActivity extends Activity {
    ....
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            ...
            // in this case 'this' refers the current activity instance
            // (but of course you can also use MyActivity.this
            myAdapter = new ArrayAdapter(this, R.layout.list_item, items);
    
            ...
    
            myButton.setOnClickListener(new OnClickListener() {
                 @Override
                     public void onClick(View arg0) {
                         // here you must use ActivityName.this because
                         // 'this' refers to the OnClickListner instance
                         Intent intent = new Intent(ActivityName.this, AnotherActivityNameActivityName.class);
                         startActivity(intent);
                     }
            });
    
            ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

new AlertDialog.Builder(this) .setMessage(mymessage) .setTitle(title) .setCancelable(true) .setNeutralButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int
I have created an AlertDialog using AlertDialog.Builder, but the Dialog border takes up too
public class IdAsync extends AsyncTask<String, Void, Void> { AlertDialog alertDialog = new AlertDialog.Builder(MainClass.this).create(); protected
AlertDialog.Builder alt_bld = new AlertDialog.Builder(this); when i wrote this error is shawn that The
@Override protected Dialog onCreateDialog (int id) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.instant_alert_screen_title); builder.setInverseBackgroundForced(true);
AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(Title); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,
I'm creating an Alert dialog by using the following: AlertDialog.Builder builder = new AlertDialog.Builder(context);
I currently have this: Builder yesandno = new AlertDialog.Builder(this); yesandno.setTitle(QuickResponse); yesandno.setMessage(message); yesandno.setPositiveButton(YES, null); yesandno.setNegativeButton(NO,
I am using this alert dialog: public void displayAlert() { new AlertDialog.Builder(getActivity()).setMessage(R.string.invitenotice) .setTitle(Invite Notice)
Heres my code: AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle(What's Your name?); alert.setMessage(Seems like you're

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.