Getting data from OFActvity and viceversa

#1

Hi! i’m been using the androidMultiOFactivity, i wonder how is get dataflow between ofApp.cpp and android activity in this case the example OFActivityA, also is possible to each activity have they of ofApp.h?

#2

Hi ! i found this
http://relabtive.com/blog/2014/11/usar-jni-en-openframeworks-android-parte-iii/

But is crashing and also the tutorial is calling jni object a just want to get a in
int or call a method, can someone help me here?

also it says in the .cpp

/**

  • Communication between Java and Openframeworks, useful for calling native methods (call C++ into Java)

  • This is a method without parameters , if you want to pass (for example) an ‘int’ the code would be:

  • Java_cc_openframeworks_activitiesOF_OFActivity_callCmethod(JNIEnv *, jobject, jint foo)

  • For more Primitive Types and Native Types see:

But no really sure how to do it.

#4

Okay, i found this old post, i’m able to pass a string from java to OF but using OFAndroid not OFActivity a.


Here is the code

static public boolean getStringToCppSide() {
    return "String from Java side!";
}

ofApp.h:

std::string getJavaString();

ofApp.cpp:

void ofApp::setup() {
    //add this line to the end of setup:
    ofLogNotice("ofApp.cpp") << "Received string:" << getJavaString();
}


std::string ofApp::getJavaString() {
    jmethodID midCallBackStatic = ofGetJNIEnv()->GetStaticMethodID(ofGetJavaOFAndroid(), "getStringToCppSide", "()Ljava/lang/String;");
    jstring resultJNIStr = (jstring)ofGetJNIEnv()->CallStaticObjectMethod(ofGetJavaOFAndroid(), midCallBackStatic);
    const char *resultCStr = ofGetJNIEnv()->GetStringUTFChars(resultJNIStr, NULL);
    std::string resultStr(resultCStr);
    ofGetJNIEnv()->ReleaseStringUTFChars(resultJNIStr, resultCStr);
    return resultStr;
}

But how can i get the variable from OFActivity?

Already, try it passing the variable to OFAndroid but the code is not working intent function cannot been found:

OFActivitya
Intent sendStuff = new Intent(this, OFAndroid.class);
sendStuff.putExtra(key, stringvalue);
startActivity(sendStuff);

OFAndroid

Intent startingIntent = getIntent();
String whatYouSent = startingIntent.getStringExtra(key, value);

Hi @Rancs how can i pass the variable to OFAndroid?