I could show dialog if I uses an Activity instance but when I uses Context or Application Context instance Dialog is not showing.
AlertDialog.Builder builder = n
This is one of the MOST important things that you must always remember about Contexts. There are 2 types of contexts, Activity contexts
and Application contexts
. You will observe in many UI related classes, a Context is passed. This is not the Application context! In such cases you must always pass an Activity Context. Except for a Toast
, no other UI component will work with Application context.
Application Context is always passed when you want some service or component which is Application related, like the Telephony Manager, Location Manager etc.
For UIs, you must always pass a context that is UI related which is the Activity.