-
getApplicationContext ()
returns the application context of the entire application life cycle,when application will destroy then it will destroy also. -
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 theSpinner
instance because we are using this withinonItemSelected(AdapterView<?>arg0, View arg1, int arg2, long arg3)
method which is fromSpinner
class andSpinner
inherit this method fromAdapterView.OnItemSelectedListener
interface -
getBaseContext()
is the method ofContextWrapper
. AndContextWrapper
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 documention then this method require an 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.