Commit 410a599d authored by yuweih's avatar yuweih Committed by Commit bot

[Remoting Android] Fix split-screen crash

Previously we assumed that DestopView.onAttachedToWindow() will only be called
after DesktopView.init() is called but this is not true when we enter split
screen mode. Since the lifecycle of View.onAttached... and View.onDetached in
relate to Activity.onCreate() and Activity.onDestroy() is not well documented
and behaves quite surprisingly, it may be better to just rely on the lifecycle
of the activity itself.

This CL removes DesktopView's onAttachedToWindow() and onDetachedFromWindow()
overrides and handles initialization and invalidation by Desktop's onCreate()
and onDestroy().

BUG=647823

Review-Url: https://codereview.chromium.org/2348563004
Cr-Commit-Position: refs/heads/master@{#419343}
parent cfad0a79
...@@ -177,6 +177,12 @@ public class Desktop ...@@ -177,6 +177,12 @@ public class Desktop
mClient.enableVideoChannel(false); mClient.enableVideoChannel(false);
} }
@Override
protected void onDestroy() {
mRemoteHostDesktop.destroy();
super.onDestroy();
}
/** Called to initialize the action bar. */ /** Called to initialize the action bar. */
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
......
...@@ -25,8 +25,6 @@ public final class DesktopView extends SurfaceView { ...@@ -25,8 +25,6 @@ public final class DesktopView extends SurfaceView {
/** The parent Desktop activity. */ /** The parent Desktop activity. */
private Desktop mDesktop; private Desktop mDesktop;
private RenderStub mRenderStub;
private TouchInputHandler mInputHandler; private TouchInputHandler mInputHandler;
private InputEventSender mInputEventSender; private InputEventSender mInputEventSender;
...@@ -42,27 +40,22 @@ public final class DesktopView extends SurfaceView { ...@@ -42,27 +40,22 @@ public final class DesktopView extends SurfaceView {
*/ */
public void init(Client client, Desktop desktop, RenderStub renderStub) { public void init(Client client, Desktop desktop, RenderStub renderStub) {
Preconditions.isNull(mDesktop); Preconditions.isNull(mDesktop);
Preconditions.isNull(mRenderStub); Preconditions.isNull(mInputHandler);
Preconditions.isNull(mInputEventSender); Preconditions.isNull(mInputEventSender);
Preconditions.notNull(desktop); Preconditions.notNull(desktop);
Preconditions.notNull(renderStub); Preconditions.notNull(renderStub);
mDesktop = desktop; mDesktop = desktop;
mRenderStub = renderStub;
mInputEventSender = new InputEventSender(client); mInputEventSender = new InputEventSender(client);
renderStub.setDesktopView(this);
mInputHandler = new TouchInputHandler(this, mDesktop, renderStub, mInputEventSender);
} }
@Override /**
public void onAttachedToWindow() { * Destroys the view. Should be called in {@link android.app.Activity#onDestroy()}.
Preconditions.isNull(mInputHandler); */
super.onAttachedToWindow(); public void destroy() {
mRenderStub.setDesktopView(this);
mInputHandler = new TouchInputHandler(this, mDesktop, mRenderStub, mInputEventSender);
}
@Override
public void onDetachedFromWindow() {
mInputHandler.detachEventListeners(); mInputHandler.detachEventListeners();
super.onDetachedFromWindow();
} }
// TODO(yuweih): move showActionBar and showKeyboard out of this class. // TODO(yuweih): move showActionBar and showKeyboard out of this class.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment