getApplicationContext :
As per Developer documention : getApplicationContext
Return the context of the single, global Application object of the current process. This generally should only be used if you need a Context whose lifecycle is separate from the current context, that is tied to the lifetime of the process rather than the current component.
Use:
You can use throughout your application with the help of getting Application context using
public class YourApp extends Application
{
static YourApp appstate;
public void onCreate(Bundle savedInstanceState){
super.onCreate();
appstate = this;
}
public static YourApp getApplication(){
return appstate;
}
}
How to use it : YourApp.getApplication();
this
Within an instance method or a constructor, this is a reference to the current object.
Use: You can use as along as you can see your Activity Context
e.g.
public void onCreate(Bundled savedInstanceState)
{
...
Toast.makeText(this, "HI", Toast.LENGTH_LONG).show();
}
How one can differentiate use of this
and getApplicationContext()
using Toast.makeText()
?
Try to use Toast.makeText() in AynscTask
with this
and getApplicationContext
.