提交 60681a23 编写于 作者: J Jason Simmons 提交者: GitHub

Do not dispatch UI events if they arrive after the FlutterView has been destroyed (#3306)

Fixes https://github.com/flutter/flutter/issues/7234
上级 c677a1b7
......@@ -157,6 +157,9 @@ public class FlutterView extends SurfaceView
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (!isAttached())
return super.onKeyUp(keyCode, event);
try {
JSONObject message = new JSONObject();
message.put("type", "keyup");
......@@ -171,6 +174,9 @@ public class FlutterView extends SurfaceView
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (!isAttached())
return super.onKeyDown(keyCode, event);
try {
JSONObject message = new JSONObject();
message.put("type", "keydown");
......@@ -377,6 +383,9 @@ public class FlutterView extends SurfaceView
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!isAttached())
return false;
// TODO(abarth): This version check might not be effective in some
// versions of Android that statically compile code and will be upset
// at the lack of |requestUnbufferedDispatch|. Instead, we should factor
......@@ -419,6 +428,9 @@ public class FlutterView extends SurfaceView
@Override
public boolean onHoverEvent(MotionEvent event) {
if (!isAttached())
return false;
boolean handled = handleAccessibilityHoverEvent(event);
if (!handled) {
// TODO(ianh): Expose hover events to the platform,
......@@ -449,6 +461,10 @@ public class FlutterView extends SurfaceView
mNativePlatformView = nativeAttach(this);
}
private boolean isAttached() {
return mNativePlatformView != 0;
}
private void preRun() {
resetAccessibilityTree();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册