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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:08:46+00:00 2026-05-29T06:08:46+00:00

First the format of Toast.makeText(): public static Toast makeText (Context context, CharSequence text, int

  • 0

First the format of Toast.makeText():

public static Toast makeText (Context context, CharSequence text, int duration)
the first argument is Context, the function getApplicationContext() also return the current context, everything is ok, but IMO, the getApplicationContext() can also be replaced with this, just as follows:

public class ContextMenuResourcesActivity extends Activity {
    /** Called when the activity is first created. */

    private Button b1;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    b1 = (Button)findViewById(R.id.button1);
    final int l = Toast.LENGTH_LONG;
    final String s1 = "some string";
    b1.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Toast t1 = Toast.makeText(this, s1, l);
                t1.show();
            }
        });
    }
}

IMO this stands for the class ContextMenuResourcesActivity, which extends Context, so it can replace the first argument which demands for Context, but I failed, can anyone explain why?

  • 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-29T06:08:48+00:00Added an answer on May 29, 2026 at 6:08 am

    When you create a new OnClickListener, you are creating a anonymous class which implements a particular interface. Thus, this does not refer to the Activity, since you are actually in another object.

    Here’s some more info on the subject Anonymous classes vs delegates

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

Sidebar

Related Questions

On my input id='currency' First I want maskMoney for currency format $(function () {
I was just reading this line: The first thing the format() method does is
First, how do I format the XML processing instruction, is it: <?processingInstructionName attribute=value attribute2=value2?>
first time SO user :) I know that I can format a number like
I have a data set with the following format The first and second fields
this is my first time at stack overflow so I'm sorry if the format
First, 2 common (basic) approaches: # returning from some FoosController method respond_to do |format|
I'm trying to design my first file format in ProtoBuf, and I'm not sure
First time user - hoping this is in the right format: I am wanting
First of all, I'm kinda new to the barcode formats and what I do

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.