I am using the following code
class AddTask extends AsyncTask<Void, Void, Void>
{
ProgressDialog dialog;
protected void onPreExecute()
{
dialog = new ProgressDialog(getApplicationContext());
dialog.setMessage("Loading");
dialog.setIndeterminate(true);
dialog.setCancelable(false);
dialog.show();
}
protected Void doInBackground(Void... unused)
{
//task
return(null);
}
protected void onPostExecute(Void unused)
{
dialog.dismiss();
}
}
I am calling it from here
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
new AddTask.execute();
}
Logcat
03-29 18:16:06.434: E/AndroidRuntime(1246): Caused by: android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an application
i think you got exception due to this line
plz use this instead of getApplicationContext() or you can also use YourActivity.this for solve this issue.