If you read the documentation at getApplicationContext()
you find that you should only use this if you need a Context
whose lifecycle is separate from the current context. This doesn't apply in your examples and use of this
object as an object of type className.I think here you can use
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
OR
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ClassNAme.this);
Both should work.