当我开始自由行走活动时,我正在接触窗户。我已经处理了这种情况,但仍然不明白我为什么还要这样做。
这是我的代码:
private void showPopUp() {
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); //before
dialog.setContentView(R.layout.wwmove_screen_popup);
TextView mNo = (TextView) dialog.findViewById(R.id.move_no);
// if button is clicked, close the custom dialog
mNo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
TextView mYes = (TextView) dialog.findViewById(R.id.moveyes);
mYes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
killAll();
storeSegmentcompletdInformation("skipped");
storeOneDayInformation("skipped");
Intent gotoSummary = new Intent(WwFreeWalkMoveActivity.this, WwFreeWalkSummaryActivity.class);
gotoSummary.putExtra(ParamConstants.SUMMARY_GOOGLEFIT_KEY, String.valueOf(stepCountGoogleFit));
startActivity(gotoSummary);
}
});
dialog.show();
}
我得到的错误是:
08-18 10:38:53.172 28118-28118/com.mobiefit.walk E/WindowManager: android.view.WindowLeaked: Activity com.mobiefit.walk.freewalk.activity.WwFreeWalkMoveActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{21f913f9 V.E..... R.....I. 0,0-960,516} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:364)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:274)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
at android.app.Dialog.show(Dialog.java:298)
at com.mobiefit.walk.freewalk.activity.WwFreeWalkMoveActivity.showPopUp(WwFreeWalkMoveActivity.java:953)
at com.mobiefit.walk.freewalk.activity.WwFreeWalkMoveActivity.onOptionsItemSelected(WwFreeWalkMoveActivity.java:1806)
at android.app.Activity.onMenuItemSelected(Activity.java:2936)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:404)
at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:185)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:100)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:100)
at android.support.v7.widget.ToolbarWidgetWrapper$1.onClick(ToolbarWidgetWrapper.java:192)
at android.view.View.performClick(View.java:4785)
at android.view.View$PerformClick.run(View.java:19888)
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:5273)
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:908)
谁能告诉我我做错了什么?
答案 0 :(得分:0)
窗口泄露的异常通常是由未正确解除的对话框引起的。 你必须解雇对话框 在你的代码中 使用这个
dialog.dismiss();
mYes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
killAll();
storeSegmentcompletdInformation("skipped");
storeOneDayInformation("skipped");
Intent gotoSummary = new Intent(WwFreeWalkMoveActivity.this, WwFreeWalkSummaryActivity.class);
gotoSummary.putExtra(ParamConstants.SUMMARY_GOOGLEFIT_KEY, String.valueOf(stepCountGoogleFit));
startActivity(gotoSummary);
}
});
答案 1 :(得分:0)
在继续下一个活动或任务之前。关闭你的dialog.dismiss();
对话框。
public void onClick(View v) {
killAll();
storeSegmentcompletdInformation("skipped");
storeOneDayInformation("skipped");
Intent gotoSummary = new Intent(WwFreeWalkMoveActivity.this, WwFreeWalkSummaryActivity.class);
gotoSummary.putExtra(ParamConstants.SUMMARY_GOOGLEFIT_KEY, String.valueOf(stepCountGoogleFit));
dialog.dismiss(); // here you just have to add one line.
startActivity(gotoSummary);
}