If you are creating a custom Dialog for Android, and using “getApplicationContext()” to pass the application context in the dialog, then most likely you would have faced a Force Close with this exception showing up in logcat.
Uncaught handler: thread main exiting due to uncaught exception
android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an application.
The context you pass to the ProgressDialog must be an activity and not anApplication
dialog = ProgressDialog.show(getApplicationContext(), “Please wait…”,”Retrieving data …”, true);
dialog = ProgressDialog.show(this, “Please wait…”,”Retrieving GPS data …”, true);
Explanation: getApplicationContext() returns a context which is for the application itself and not the activity, while “this” would give you the context of the activity in which you are creating the dialog.