Possible Duplicate:
Android - what's the difference between the various methods to get a Context?
I want to know what's the difference between using this
, ClassName.this
, getApplicationContext()
or myContext
?
What are the effects of using each as context in the Toast below?
public class ClassName extends Activity {
final ClassName myContext = this;
...
public void onCreate(Bundle savedInstanceState) {
...
button.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "This is a toast", Toast.LENGTH_LONG).show();
}
});
}
Can you point me to a detailed explanation for contexts? I have read Romain Guy's post here. Maybe a few more examples could help :)