我目前正在使用某些应用程序并进行探索,但遇到此错误。这只是偶然发生的,更早之前看起来还不错。
我阅读了一些与问题有关的问题,但是我无法将代码与它们联系起来,所以我感到很困惑。我仍然是初学者,所以将不胜感激。
Logcat
4386-4386/com.example.gab.quadrantms E/WindowManager: android.view.WindowLeaked: Activity com.example.gab.quadrantms.Home has leaked window DecorView@abb868f[] that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:576)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:363)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:128)
at android.app.Dialog.show(Dialog.java:454)
at com.example.gab.quadrantms.SurveysFragment$1$1$1.onDataChange(SurveysFragment.java:120)
片段
if (getActivity() != null) {
if (myPosition.equals("Project Manager")) {
bottomSheetDialog = new BottomSheetDialog(getActivity());
final View bottomSheetDialogView = getLayoutInflater().inflate(R.layout.bottom_dialog_layot, null);
bottomSheetDialog.setContentView(bottomSheetDialogView);
View viewView = bottomSheetDialogView.findViewById(R.id.view);
View assignView = bottomSheetDialogView.findViewById(R.id.assign);
View deleteView = bottomSheetDialogView.findViewById(R.id.delete);
bottomSheetDialog.show(); //THIS LINE WHERE THE ERROR IS POINTING
if (bottomSheetDialog.isShowing()) {
assignView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String id = viewHolder.setSurveyID(model.getSurveyID());
String loc = viewHolder.setSurveyLocation(model.getSurveyLocation());
String type = viewHolder.setSurveyType(model.getSurveyType());
String progress = viewHolder.setProgress(model.getProgress());
if (progress.equals("Finished")) {
Toast.makeText(getContext(), "This project is Already Finished.", Toast.LENGTH_SHORT).show();
} else {
Intent surveyAssign = new Intent(getActivity(), AssignActivity.class);
surveyAssign.putExtra("id", id);
surveyAssign.putExtra("loc", loc);
surveyAssign.putExtra("type", type);
surveyAssign.putExtra("progress", progress);
startActivity(surveyAssign);
getActivity().finish();
}
}
});
deleteView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder message = new AlertDialog.Builder(getContext());
message.setMessage("Are you sure you want to Delete this Project?").setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, int which) {
String id = viewHolder.setSurveyID(model.getSurveyID());
mRemoveDuplicate = FirebaseDatabase.getInstance().getReference().child("Surveys");
mRemoveDuplicate.child(id).removeValue().addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(getContext(), "Project Deleted.", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog alert = message.create();
alert.setTitle("Message");
alert.show();
}
});
答案 0 :(得分:0)
请在运行片段的所有对话框中添加您的活动名称。
例如。
bottomSheetDialog = new BottomSheetDialog(YourActivity.this);
AlertDialog.Builder message = new AlertDialog.Builder(YourActivity.this);
希望这对您有帮助!
谢谢。
答案 1 :(得分:0)
应用何时崩溃?是显示对话框时还是关闭对话框时。 如果在关闭对话框时出现问题,请检查是否正确关闭了该对话框。
当您完成父活动之前正确退出对话框时,会出现WindowLeaked 错误。
注意:如果在 assignView 上的OnClick期间应用程序崩溃,则可能是在OnClickListener中getActivity().finish();
处完成活动的问题。