I am new to Android and may be what i am asking is very silly one..so please forgive me
To create AlertDialog…. standard way is to call
AlertDialog alertDialog = new AlertDialog.Builder(Context here....).create();
then
alertDialog.show();
But i tried via 3 ways…
way 1
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
way 2
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
way 3
AlertDialog alertDialog = new AlertDialog.Builder(this.getApplicationContext()).create();
First 2 works fine but 3rd one gives illegalSTateException……
so my query is why it is giving that????
Thanks
This question’s answer will help you understand the different types of contexts in android
Difference between getContext() , getApplicationContext() , getBaseContext() and "this"
Related to your error, android probably don’t want your AlertDialog to be tied to the entire app context, but just to the activity’s.