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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:30:41+00:00 2026-05-31T02:30:41+00:00

this often to reference to current context. But, at some case, why we must

  • 0

this often to reference to current context. But, at some case, why we must use getBaseContext() instead of this. (It means when use this will notice error).

Here is my example:

Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.setAdapter(adapter);            
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?>arg0, View arg1, int arg2, long arg3){
       Toast.makeText(getBaseContext(),"SELECTED", Toast.LENGTH_SHORT).show(); //this line
    }

At above code, when I change getBaseContext() to this will receive error.

Who can explain for me, please.

  • 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-31T02:30:43+00:00Added an answer on May 31, 2026 at 2:30 am
    1. getApplicationContext () returns the application context of the entire application life cycle,when application will destroy then it will destroy also.

    2. this the context returns the current context of the activity, belong to the activity, the activity is destroyed then it will destroy also.but in your case it will refers to the Spinner instance because we are using this within onItemSelected(AdapterView<?>arg0, View arg1, int arg2, long arg3) method which is from Spinner class and Spinner inherit this method from AdapterView.OnItemSelectedListener interface

    3. getBaseContext() is the method of ContextWrapper. And ContextWrapper is, "Proxying implementation of Context that simply delegates all of its calls to another Context. Can be subclassed to modify behavior without changing the original Context." (as per javadocs)..

    and in your case :Spinner class is not subclass of Context or ContextWrapper class*

    Toast.makeText(getBaseContext(),"SELECTED", Toast.LENGTH_SHORT).show();
    

    means getBaseContext() is method of ContextWrapper and ContextWrapper is Proxying implementation of Context so indirectly we are passing an Context Class Object.

    or we can also pass ‘Activity.this’ because Activity class is subclass of ContextWrapper class .

    if you go with Android documentation then this method requires a Context class object:
    public static Toast makeText (Context context, int resId, int duration)

    so we are not able to pass an activity or class context means this to Toast.makeText which don’t have a subclass of either Context or ContextWrapper class.

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

Sidebar

Related Questions

I often use this code pattern: while(true) { //do something if(<some condition>) { break;
Often times applications will need some database code tables (aka reference tables or domain
In .NET, strings are immutable and are reference type variables. This often comes as
I see this often in the build scripts of projects that use autotools (autoconf,
I use a pattern that looks something like this often. I'm wondering if this
This is often situation, but here is latest example: Companies have various contact data
I often use this recursive 'visitor' in F# let rec visitor dir filter= seq
We use the example.com often for domain name reference. I wonder if any IP
Without automatic reference counting you often write code like this, when adding a new
This often comes up: your application has gotten extensive enough that it's time to

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.