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