fix multi Activity support

jobjects have to be compared with env->IsSameObject()
and each Activity needs its own Window instance.
The GtkWindow is still shared between all Activities
This commit is contained in:
Julian Winkler
2023-08-22 13:20:04 +02:00
parent 3fd81baeaf
commit 3399c84e84
3 changed files with 17 additions and 4 deletions

View File

@@ -86,10 +86,19 @@ void activity_start(JNIEnv *env, jobject activity_object) {
}
JNIEXPORT void JNICALL Java_android_app_Activity_nativeFinish(JNIEnv *env, jobject this, jlong window) {
activity_backlog = g_list_remove(activity_backlog, this);
GList *l;
jobject removed_activity = NULL;
for (l = activity_backlog; l != NULL; l = l->next) {
if ((*env)->IsSameObject(env, this, l->data)) {
removed_activity = l->data;
activity_backlog = g_list_delete_link(activity_backlog, l);
break;
}
}
activity_update_current(env);
activity_close(env, this);
_UNREF(this);
if (removed_activity)
_UNREF(removed_activity);
if (activity_backlog == NULL)
gtk_window_close(GTK_WINDOW(_PTR(window)));
}

View File

@@ -110,6 +110,8 @@ public class Activity extends Context {
protected void onStart() {
System.out.println("- onStart - yay!");
if (window.contentView != null)
window.setContentView(window.contentView);
return;
}
@@ -232,7 +234,7 @@ public class Activity extends Context {
Constructor<? extends Activity> constructor = cls.getConstructor();
Activity activity = constructor.newInstance();
activity.intent = intent;
activity.window = getWindow();
activity.getWindow().native_window = getWindow().native_window;
nativeStartActivity(activity);
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
onActivityResult(requestCode, 0 /*RESULT_CANCELED*/, new Intent()); // RESULT_CANCELED is the only pre-defined return value, so hopefully it works out for us
@@ -250,7 +252,7 @@ public class Activity extends Context {
Constructor<? extends Activity> constructor = cls.getConstructor();
Activity activity = constructor.newInstance();
activity.intent = intent;
activity.window = getWindow();
activity.getWindow().native_window = getWindow().native_window;
nativeStartActivity(activity);
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();

View File

@@ -20,6 +20,7 @@ public class Window {
// FIXME private
public long native_window;
public View contentView;
private Window.Callback callback;
@@ -39,6 +40,7 @@ public class Window {
}
public void setContentView(View view) {
contentView = view;
set_widget_as_root(native_window, view.widget);
}