You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
MessageQueue: integrate with glib main loop
Adds a special treatment for the main Looper to not block in java code, but instead return to glib managed thread loop. Timeouts in the mainloop are now handled using g_timeout_add_full(). Also defer Activity construction, so that every thing is set up properly when the constructor runs.
This commit is contained in:
@@ -50,7 +50,7 @@ public final class MessageQueue {
|
||||
|
||||
private native static long nativeInit();
|
||||
private native static void nativeDestroy(long ptr);
|
||||
private native static void nativePollOnce(long ptr, int timeoutMillis);
|
||||
private native static boolean nativePollOnce(long ptr, int timeoutMillis);
|
||||
private native static void nativeWake(long ptr);
|
||||
private native static boolean nativeIsIdling(long ptr);
|
||||
|
||||
@@ -134,7 +134,9 @@ public final class MessageQueue {
|
||||
|
||||
// We can assume mPtr != 0 because the loop is obviously still running.
|
||||
// The looper will not call this method after the loop quits.
|
||||
nativePollOnce(mPtr, nextPollTimeoutMillis);
|
||||
if (nativePollOnce(mPtr, nextPollTimeoutMillis)) {
|
||||
return null; // thread is managed by glib, so return instead of blocking
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
// Try to retrieve the next message. Return if found.
|
||||
|
||||
Reference in New Issue
Block a user