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

I was able to pass data from ofActivity to ofApp.cpp here the code:

OFActivity.cpp


OFAndroid of = new OFAndroid("jala");

OFAndroid

private static String text ;

public OFAndroid(String text) {
	this.text = text ;
}


public void useText() {
	Log.e("TAG" , this.text);
}


String variableToStoreStringInClass;

public void setString(String yourString){

	variableToStoreStringInClass = text;
}

static public String getStringToCppSide() {

	return text;
}

ofApp.cpp


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;
}
#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?