I tried starting a new activity from C++ with help of JNI and it was started successfully. But now I need to get result of the started Activity.
Starting activity:
jobject activity = helper->GetActivity();
jclass activity_class = env->GetObjectClass(activity);
jclass class_intent = env->FindClass("android/content/Intent");
jmethodID newIntent = env->GetMethodID(class_intent, "<init>", "()V");
jobject intent = env->NewObject(class_intent, newIntent);
jmethodID startActivityMethod = env->GetMethodID(activity_class, "startActivityForResult", "(Landroid/content/Intent;I)V");
jint callid = (jint) 1001;
env->CallVoidMethod(activity, startActivityMethod, intent, callid);
So, i understand that Java calls "onActivityResult" function, but i don't understand how to override this function in C++ using JNI.
Or may be there are some other ways to take result of started activity?
I tried to get result with help of JNI function:
extern "C" JNIEXPORT void JNICALL Java_package_class_onActivityResult(JNIEnv * env, jobject, jobject activity, jint requestCode, jint resultCode, jobject intentObject) {
Logger::Instance().LogInfo(L"Java_package_class_onActivityResult");
}
But this function has not called (mb not overridden?)
Also I tried to call a new function create
C++ Code:
extern "C" JNIEXPORT void JNICALL Java_iboxPro1C_iboxProActivity_nativeActivityResult(JNIEnv* env, jobject obj, jobject data) {
Logger::Instance().LogInfo(L">>>JNIEnv.Java_iboxPro1C_iboxProActivity_onActivityResult");
Logger::Instance().LogInfo(L"<<<JNIEnv.Java_iboxPro1C_iboxProActivity_onActivityResult");
}
Java Code:
public class myActivity extends AppCompatActivity implements PaymentControllerListener {
static native void nativeActivityResult(Intent data);
//called when activity have to be finished.
public void FinishActivity(boolean success, Intent intent) {
Log("FinishActivity");
setResult(success ? RESULT_OK : RESULT_CANCELED, intent);
if (mService != null)
mService.stopSelf();
try {
nativeActivityResult(intent);
Log("nativeActivityResult NO exception.");
}catch(Exception exc){
Log("nativeActivityResult exception.");
Log(exc.toString());
}
finish();
}
}
Process just crash while FinishActivity (it isn't log anything).