My android application compirises two Activities: “.MainActivity” and “android.app.NativeActivity”. The latter is implemented purely in C++. On button click in “.MainActivity” I start a native one trying to pass some parameters:
public void pressedButton(View view)
{
Intent intent = new Intent(this, android.app.NativeActivity.class);
intent.putExtra("MY_PARAM_1", 123);
intent.putExtra("MY_PARAM_2", 321);
startActivity(intent);
}
How do I get MY_PARAM_1 and MY_PARAM_2 from within android.app.NativeActivity’s entry point (that is a C-function void android_main(struct android_app* state))?
In the
android_appstructure there’s a data member calledactivityof typeANativeActivity*. Inside the latter, there’s aJavaVM *vmand a misleadingly calledjobject clazz. Theclazzis actually a JNI-compliant object instance pointer to a Java object of typeandroid.app.NativeActivity, which has allActivitymethods, includinggetIntent().There’s a
JNIEnvthere, too, but it looks like it’s not attached to the activity’s main thread.Use JNI invokations to retrieve the intent, then extras from the intent. It goes like this: