I call a NativeActivity from a JavaActivity. The entry point of my NativeActivity is
android_main(struct android_app* state)
At the end of this, I call
ANativeActivity_finish
However my native activity just hangs, instead of returning to the Java Activity that called it (it was called simply using startActivity
). It seems like it is in a pause state. The only way I can get it to return to the previous activity is by calling exit(0)
at the end of my android_main, however this kills the process and causes other issues.
How can I successfully exit my NativeActivity and return to the JavaActivity that called it?
I run into the same problem. Basically it works for me when ANativeActivity_finish(..) is called in the main loop, because it invalidates the states and finishes the app itself by setting state->destroyRequested to 1 after calling ANativeActivity_finish(..) in static void android_app_destroy(struct android_app* android_app) (android_native_app_glue.c C:173).
Well it is too late for you I guess, but I spent so much time on it because I couldn't find a sultion so I post it here for everyone who runs into the same problems. More about other tricky stuff related to the detach and attach calls can be found here: Access Android APK Asset data directly in c++ without Asset Manager and copying
A solution that finally worked for me to finish a (subclass of a)
NativeActivity
from the app (native side) was calling a java method that runsfinish()
on the UI thread.C/C++ side:
Java side: