我读了一些关于这个主题的帖子,我试过这样:
@Override
public void onSuccess(String s) {
Log.d("TestFFmpeg", "SUCCESS with output : " + s);
progressDialog = new ProgressDialog(getApplicationContext());
progressDialog.setTitle("Server request");
progressDialog.setCancelable(false);
progressDialog.setMessage("Waiting response from server...");
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
progressDialog.show();
}
});
final Response response = httpClient.newCall(request).execute();
if (!response.isSuccessful()) {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
progressDialog.dismiss();
}
});
}
我提到我在课堂上使用了相同的进度对话框,我解除了它。
如果我像这样运行应用程序,我收到此错误:
android.view.WindowManager $ BadTokenException:无法添加窗口 - token null不适用于应用程序
我应该改变什么?
答案 0 :(得分:1)
Dialog
需要活动背景。
将ProgressDialog
初始化更改为
progressDialog = new ProgressDialog(MainActivity.this);