我已經通過谷歌搜索,但所有我發現開不與我的問題的答案......如何擺脫「漏窗」?
還有就是我的錯誤日誌
Activity com.fittingroom.newtimezone.view.ActivityAcceptNotAccept has leaked window com.android.internal.policy.PhoneWindow$DecorView{57b68a6 V.ED..... R......D 0,0-324,534} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:565)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:326)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
at android.app.Dialog.show(Dialog.java:350)
at com.fittingroom.newtimezone.view.ActivityAcceptNotAccept.openProgress(ActivityAcceptNotAccept.java:125)
at com.fittingroom.newtimezone.presenters.PresenterActivityAcceptNotAccept.openProgress(PresenterActivityAcceptNotAccept.java:125)
at com.fittingroom.newtimezone.presenters.PresenterActivityAcceptNotAccept.access$000(PresenterActivityAcceptNotAccept.java:16)
at com.fittingroom.newtimezone.presenters.PresenterActivityAcceptNotAccept$1.onPreExecute(PresenterActivityAcceptNotAccept.java:35)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:604)
at android.os.AsyncTask.execute(AsyncTask.java:551)
at com.fittingroom.newtimezone.presenters.PresenterActivityAcceptNotAccept.setCroppedPreviewImage(PresenterActivityAcceptNotAccept.java:51)
at com.fittingroom.newtimezone.view.ActivityAcceptNotAccept.accept(ActivityAcceptNotAccept.java:63)
at java.lang.reflect.Method.invoke(Native Method)
at android.view.View$DeclaredOnClickListener.onClick(View.java:4735)
at android.view.View.performClick(View.java:5697)
at android.view.View$PerformClick.run(View.java:22526)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
我在做什麼,我只是創建進度對話框,並在assynk任務的控制研究,並在onPreExecute()
對話框中onPostExecute()
對話框打開,因此被關閉......
有我的代碼
public final class ActivityAcceptNotAccept extends Activity implements IActivityAcceptNotAccept {
private Dialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_accept_not_accept);
...///
presenter.initView();
}
...///
@Override
public void initView() {
progressDialog = UtilClass.getDialog(ActivityAcceptNotAccept.this, getString(R.string.loading));
}
public final void accept(View view) {
switch (count) {
case firstClick:
presenter.setCroppedPreviewImage();
break;
case secondClick:
presenter.setResultOkAndFinishActivity();
break;
}
}
@Override
public void setDisplaySize() {
UtilClass.setDisplaySize(getWindowManager().getDefaultDisplay(), getWindow(), 95, 95);
}
@Override
public void openProgress() {
if (progressDialog != null) {
progressDialog.show();
}
}
@Override
public void closeProgress() {
if (progressDialog != null) {
progressDialog.cancel();
progressDialog = null;
}
}
}
有whicth我提供Dialog
例如
public abstract class UtilClass {
public static Dialog getDialog(Context context, String text) {
final Dialog progressDialog = new Dialog(context);
progressDialog.setContentView(R.layout.dialog);
progressDialog.setCanceledOnTouchOutside(false);
final Window window = progressDialog.getWindow();
if (window != null) {
window.setBackgroundDrawableResource(android.R.color.transparent);
}else {
Logger.logError("window == null", new NullPointerException(), context);
}
final TextView msg = (TextView) progressDialog.findViewById(R.id.id_tv_loadingmsg);
msg.setText(text);
return progressDialog;
}
正如我可以理解沒有什麼spesial剛剛創建對話框,顯示它,並最終關閉這就是它......一個方法
爲什麼我得到這個錯誤?
我在做什麼錯?
編輯
AsynkTask
public void setCroppedPreviewImage() {
new AsyncTask<Void, Void, byte[]>() {
@Override
protected void onPreExecute() {
super.onPreExecute();
openProgress();
}
@Override
protected byte[] doInBackground(Void... voids) {
final String path = model.getImageFilePath();
final Bitmap croppedBitmap = getCroppedBitmapFromPath(path);
return getByteArrayFromBitmap(croppedBitmap);
}
@Override
protected void onPostExecute(byte[] result) {
super.onPostExecute(result);
closeProgress();
iActivityAcceptNotAccept.setPreviewImage(result);
}
}.execute();
}
在關閉第一個對話框之前,Dialog方法調用兩次時會發生此錯誤。 – sasikumar
http://stackoverflow.com/questions/12000940/android-activity-has-leaked-window-com-android-internal-policy-impl-phonewindow –
@IntelliJAmiya是的,我看到了這個答案,但它對我來說是不可能的。我調用對話只是一次...但無論如何,我必須檢查 –