I just want to know why android gives error when we write
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
whether it is right. and why it only works when we put this as a perameter.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
Applicationis a global object and so is it’sContext. Application context should be used only for things that need aContextthat is not tied to the currently running component, like anActivity.In this case, the
AlertDialogis created inside theActivity(i assume) and it needs the context of only thatActivity– hence you should usethis. The reasoning is thatAlertDialogdoes not have a life outside of its parentActivity.