the AlertDialog.Builder constructor takes a Context as its parameter :
AlertDialog.Builder (Context context),
and i found an example where the parameter is not only this but :
new AlertDialog.Builder(MyClassName.this);
Why that?
Also, i’ve already seen this thing with Activity, where this time we add .class to the name of the activity we try to reach. Can you please tell me the meaning of those 2 keywords?
Thanks a lot
The class Activity is a sub-class of Context so you can use it as parameter in your example.
Now if for instance, you are inside an onClick method (i.e. button) or inside an inner class or an asynctask, using ‘this’ would not refer the activity itself so you need to use YourActivity.this.
Instead when you see ClassName.class it usually is because you need to specify wich activity, service or whatever you want to start, in that case the parameter type is Class.
For example if you want to start an activity, you use:
For example: