ポジティブボタン付きのダイアログウィンドウを表示するアクティビティです。ボタンをクリックすると、Staticdisplay
アクティビティに移動します。アクティビティの読み込み中にプログレスバーを追加しようとしています。次のエラーが発生します。$BadTokenException: Unable to add window -- token null is not for an application
これはプロセスバーを追加するためのコードですprogressBar.show();
。この行でエラーが発生しています。このエラーから抜け出すにはどうすればよいですか。ありがとう。
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCustomTitle(title);
builder.setMessage(R.string.app_description).setPositiveButton(
"Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (Registration.isRunning == false) {
startService(new Intent(
getApplicationContext(),
Registration.class));
}
staticInfo();
if (Registration.ruid == null)
Registration.ruid = uId;
progressBar = new ProgressDialog(
getApplicationContext());
progressBar.setCancelable(true);
progressBar.setMessage("Loading Activity...");
progressBar
.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressBar.setProgress(0);
progressBar.setMax(100);
progressBar.show();
progressBarStatus = 0;
new Thread(new Runnable() {
public void run() {
while (progressBarStatus < 100) {
progressBarStatus = 100;
progressBarHandler.post(new Runnable() {
public void run() {
progressBar
.setProgress(progressBarStatus);
}
});
}
if (progressBarStatus >= 100) {
progressBar.dismiss();
startActivity(new Intent(
getApplicationContext(),
StatisticDisplay.class));
}
}
}).start();
}
});
AlertDialog alert = builder.create();
alert.show();
} else {
startActivity(new Intent(getApplicationContext(),
StatisticDisplay.class));
}
}