implement Activity.onPostCreate() and onPostResume()

These are used by androidx to handle the Fragment lifecycle
This commit is contained in:
Julian Winkler
2024-10-05 16:52:53 +02:00
parent 21a75d7ff0
commit 1b46d728e3
4 changed files with 22 additions and 0 deletions

View File

@@ -54,6 +54,10 @@ static void activity_focus(JNIEnv *env, jobject activity)
if((*env)->ExceptionCheck(env))
(*env)->ExceptionDescribe(env);
(*env)->CallVoidMethod(env, activity, handle_cache.activity.onPostResume);
if((*env)->ExceptionCheck(env))
(*env)->ExceptionDescribe(env);
(*env)->CallVoidMethod(env, activity, handle_cache.activity.onWindowFocusChanged, true);
if((*env)->ExceptionCheck(env))
(*env)->ExceptionDescribe(env);
@@ -129,6 +133,10 @@ void _activity_start(JNIEnv *env, jobject activity_object, bool recreate)
return;
}
(*env)->CallVoidMethod(env, activity_object, handle_cache.activity.onPostCreate, NULL);
if((*env)->ExceptionCheck(env))
(*env)->ExceptionDescribe(env);
if(recreate) // only allowed for toplevel, so we know for sure where in the stack it belongs
activity_backlog = g_list_append(activity_backlog, _REF(activity_object));
else

View File

@@ -67,9 +67,11 @@ void set_up_handle_cache(JNIEnv *env)
if((*env)->ExceptionCheck(env))
(*env)->ExceptionDescribe(env);
handle_cache.activity.onCreate = _METHOD(handle_cache.activity.class, "onCreate", "(Landroid/os/Bundle;)V");
handle_cache.activity.onPostCreate = _METHOD(handle_cache.activity.class, "onPostCreate", "(Landroid/os/Bundle;)V");
handle_cache.activity.onStart = _METHOD(handle_cache.activity.class, "onStart", "()V");
handle_cache.activity.onWindowFocusChanged = _METHOD(handle_cache.activity.class, "onWindowFocusChanged", "(Z)V");
handle_cache.activity.onResume = _METHOD(handle_cache.activity.class, "onResume", "()V");
handle_cache.activity.onPostResume = _METHOD(handle_cache.activity.class, "onPostResume", "()V");
handle_cache.activity.onDestroy = _METHOD(handle_cache.activity.class, "onDestroy", "()V");
handle_cache.activity.onStop = _METHOD(handle_cache.activity.class, "onStop", "()V");
handle_cache.activity.onPause = _METHOD(handle_cache.activity.class, "onPause", "()V");

View File

@@ -9,8 +9,10 @@ struct handle_cache {
struct {
jclass class;
jmethodID onCreate;
jmethodID onPostCreate;
jmethodID onStart;
jmethodID onResume;
jmethodID onPostResume;
jmethodID onWindowFocusChanged;
jmethodID onDestroy;
jmethodID onStop;

View File

@@ -148,6 +148,11 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
return;
}
protected void onPostCreate(Bundle savedInstanceState) {
System.out.println("- onPostCreate - yay!");
return;
}
protected void onStart() {
System.out.println("- onStart - yay!");
if (window.contentView != null)
@@ -177,6 +182,11 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
return;
}
protected void onPostResume() {
System.out.println("- onPostResume - yay!");
return;
}
protected void onPause() {
System.out.println("- onPause - yay!");