1
0
Fork 0

the main View is now explicitly destroyed when shutting down

This commit is contained in:
sspanak 2025-02-22 14:16:36 +02:00 committed by Dimo Karaivanov
parent 1c7bbc7508
commit 9e4658d405
4 changed files with 15 additions and 5 deletions

View file

@ -52,13 +52,13 @@ abstract public class MainViewHandler extends HotkeyHandler {
protected void cleanUp() { protected void cleanUp() {
if (mainView != null) {
mainView.removeListeners();
}
if (orientationListener != null) { if (orientationListener != null) {
orientationListener.stop(); orientationListener.stop();
orientationListener = null; orientationListener = null;
} }
if (mainView != null) {
mainView.destroy();
}
} }

View file

@ -49,6 +49,8 @@ public class TraditionalT9 extends MainViewHandler {
@Override @Override
public View onCreateInputView() { public View onCreateInputView() {
// This may get called even when not switching IMEs, but we can't reuse the previous view
// because it will cause: "IllegalStateException: The specified child already has a parent"
mainView.forceCreate(); mainView.forceCreate();
initTray(); initTray();
statusBar.setText(mInputMode); statusBar.setText(mInputMode);

View file

@ -43,8 +43,12 @@ public class MainView {
return true; return true;
} }
public void forceCreate() { public void destroy() {
main = null; main = null;
}
public void forceCreate() {
destroy();
if (!create()) { if (!create()) {
Logger.w(getClass().getSimpleName(), "Invalid MainView setting. Creating default."); Logger.w(getClass().getSimpleName(), "Invalid MainView setting. Creating default.");
main = new MainLayoutSmall(tt9); main = new MainLayoutSmall(tt9);

View file

@ -51,12 +51,16 @@ public class ResizableMainView extends MainView implements View.OnAttachStateCha
return true; return true;
} }
public void removeListeners() {
@Override
public void destroy() {
if (main != null && main.getView() != null) { if (main != null && main.getView() != null) {
main.getView().removeOnAttachStateChangeListener(this); main.getView().removeOnAttachStateChangeListener(this);
} }
super.destroy();
} }
@Override public void onViewAttachedToWindow(@NonNull View v) { setHeight(height, heightSmall, heightNumpad); } @Override public void onViewAttachedToWindow(@NonNull View v) { setHeight(height, heightSmall, heightNumpad); }
@Override public void onViewDetachedFromWindow(@NonNull View v) {} @Override public void onViewDetachedFromWindow(@NonNull View v) {}