1
0
Fork 0

9th attempt to fix the privileged options problem: removed onDestroy debugging code and explicitly destroying LanguageCollection and DataStore on shutdown

This commit is contained in:
sspanak 2025-05-13 15:44:48 +03:00 committed by Dimo Karaivanov
parent a7d4fa8318
commit d0579e9362
3 changed files with 17 additions and 12 deletions

View file

@ -40,6 +40,12 @@ public class DataStore {
}
public static void destroy() {
words = null;
pairs = null;
}
private static void runInThread(@NonNull Runnable action) {
executor.submit(action);
}

View file

@ -1,18 +1,15 @@
package io.github.sspanak.tt9.ime;
import android.Manifest;
import android.app.Dialog;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.view.Window;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import androidx.annotation.NonNull;
import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.db.DataStore;
import io.github.sspanak.tt9.db.words.DictionaryLoader;
import io.github.sspanak.tt9.hacks.InputType;
@ -248,6 +245,8 @@ public class TraditionalT9 extends MainViewHandler {
backgroundTasks.removeCallbacksAndMessages(null);
zombieChecks = SettingsStore.ZOMBIE_CHECK_MAX;
zombieDetector.removeCallbacksAndMessages(null);
LanguageCollection.destroy();
DataStore.destroy();
Logger.d(LOG_TAG, "===> Final cleanup completed");
}
@ -262,18 +261,13 @@ public class TraditionalT9 extends MainViewHandler {
cleanUp();
isDead = true;
// @todo: investigate the crash and remove this try-catch
try {
super.onDestroy();
} catch (Exception e) {
Dialog win = getWindow();
Window winwin = win != null ? win.getWindow() : null;
View keys = winwin != null ? winwin.findViewById(R.id.main_soft_keys) : null;
boolean hasWindowToken = keys != null && keys.getWindowToken() != null;
boolean hasAppToken = keys != null && keys.getApplicationWindowToken() != null;
String shutdownDebug = "Window token: " + hasWindowToken + "; App token: " + hasAppToken + "; main view: " + (keys != null) + "; window.window: " + (winwin != null) + "; window: " + (win != null);
throw new RuntimeException("Parent failed to destroy." + shutdownDebug);
if (mainView != null && mainView.getView() != null) {
Logger.e(LOG_TAG, "===> MainView destroy failed: " + e.getMessage() + ". Destroying manually.");
mainView.destroy();
}
}
Logger.d(LOG_TAG, "===> Shutdown completed");

View file

@ -37,6 +37,11 @@ public class LanguageCollection {
}
public static void destroy() {
self = null;
}
@Nullable
public static NaturalLanguage getLanguage(String langId) {
try {