每次显示自定义对话框时都会出现此错误,但我不明白为什么。 以下是我如何声明我的自定义对话框:
dialogueGettingAllPatients = new DialogueGettingAllPatients(this);
以下是我调用对话框并尝试在任务完成后更新其UI的方式:
dialogueGettingAllPatients.show();
for (ZoneData zone : zonesSelected) {
...
@Override
public void onResponse(Call call, Response response) throws IOException {
String rsp = response.body().string();
try {
JSONArray jsonRsp = new JSONArray(rsp);
...
dialogueGettingAllPatients.gettingDataSuccess = true;
dialogueGettingAllPatients.updateUI();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
以下是对话框的代码:
public class DialogueGettingAllPatients extends Dialog implements android.view.View.OnClickListener {
private ActivityMain activityMain;
private ImageView success, failed;
private Button ok;
private GifImageView loadingLogo;
public boolean gettingDataSuccess;
public DialogueGettingAllPatients(Activity a) {
super(a);
this.activityMain = (ActivityMain) a;
}
public void updateUI(){
if(gettingDataSuccess){
loadingLogo.setVisibility(View.GONE);
ok.setVisibility(View.VISIBLE);
success.setVisibility(View.VISIBLE);
} else {
ok.setVisibility(View.VISIBLE);
failed.setVisibility(View.GONE);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dialogue_writting_tag);
ok = (Button) findViewById(R.id.btn_ok);
success = (ImageView) findViewById(R.id.imageValid);
failed = (ImageView) findViewById(R.id.imageFailed);
loadingLogo = (GifImageView) findViewById(R.id.loadingLogo);
ok.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_ok:
dismiss();
break;
default:
break;
}
}
}
完整的堆栈跟踪:
03-21 12:46:30.818 16103-16103/E/WindowManager: android.view.WindowLeaked: ActivityMain has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{378510be V.E..... R.....I. 0,0-748,264} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:363)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:271)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
at android.app.Dialog.show(Dialog.java:298)
at ActivityMain.getPatientsInZones(ActivityMain.java:185)
at FragmentNewTrip1.downloadFiles(FragmentNewTrip1.java:225)
at FragmentNewTrip1.access$000(FragmentNewTrip1.java:60)
at FragmentNewTrip1$2.onClick(FragmentNewTrip1.java:98)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)