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:
Julian Winkler
2023-08-08 10:16:17 +02:00
parent c6c4e8b3a2
commit 4491de7f63
7 changed files with 80 additions and 29 deletions

View File

@@ -36,7 +36,7 @@ public class Activity extends Context {
* @param className class name of activity or null
* @return instance of main activity class
*/
private static Activity createMainActivity(String className) throws ClassNotFoundException, NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException {
private static Activity createMainActivity(String className, long native_window) throws ClassNotFoundException, NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException {
if (className == null) {
InputStream inStream = ClassLoader.getSystemClassLoader().getResourceAsStream("AndroidManifest.xml");
AndroidManifestBlock block = AndroidManifestBlock.load(inStream);
@@ -49,11 +49,9 @@ public class Activity extends Context {
}
Class<? extends Activity> cls = Class.forName(className).asSubclass(Activity.class);
Constructor<? extends Activity> constructor = cls.getConstructor();
return constructor.newInstance();
}
protected void set_window(long native_window) {
window.native_window = native_window;
Activity activity = constructor.newInstance();
activity.window.native_window = native_window;
return activity;
}
public Activity() {
@@ -104,12 +102,6 @@ public class Activity extends Context {
protected void onCreate(Bundle savedInstanceState) {
System.out.println("- onCreate - yay!");
/* TODO: this probably belongs elsewhere, but this is our entry point for better or worse */
Looper looper = Looper.myLooper();
if(looper == null) {
Looper.prepareMainLooper();
}
return;
}