Form leakage

  • why
  • The solution
  • Manual processing
  • System management

Windows Leaked is the latest version to Crash. Windows Leaked is the latest version to Crash

why

The reason for form leaks is simple. When we build a Dialog or PopupWindow on top of an Activity, that window depends on the Activity. Window Leaked appears if the Activity is finished when the floating Window is not dismissed. Once you know the cause of the problem, it’s easy to solve.

The solution

There are two ways to solve the problem. The first is to do a judgment process manually. The second is to let the system manage it using the onCreateDialog method.

Manual processing

Manual processing is also very convenient, that is, we can make a judgment on it.

@Override protected void onDestroy() { super.onDestroy(); // Handle window leaks in memory leaks. That is, forms on top of the Activity are attached to the Activity display (Dialog, Popup, etc.), and while they are still there, the attached Activity is gone causing if (progressDialog! = null) { progressDialog.dismiss(); }}Copy the code

System management

Override the onCreateDialog method in the Activity to let the system manage it

	@Override
	protected Dialog onCreateDialog(int id) {
	    Dialog dialog = new Dialog(this);
	    return dialog;
}
Copy the code

Here is a brief record of the problem handling