coping string from acitivity to another in native

I want to copy a string from one activity to another activity

here is my code

I want to copy the g sting to the hell string in the other activity

using namespace std;

std::string g;
std::string hell;
string hello;

extern "C"
JNIEXPORT jstring JNICALL
Java_com_example_tony_c_MainActivity_getStrLen(JNIEnv *env, jobject instance, jstring s_) {
const char *s = env->GetStringUTFChars(s_, 0);

// TODO

g="hello"; // I want this g coppied into hell in the other activity
env->ReleaseStringUTFChars(s_, s);


return env->NewStringUTF(hell.c_str());


}
extern "C"
JNIEXPORT jstring JNICALL

Java_com_example_tony_c_MainActivity_stringFromJNI(JNIEnv *env, jobject instance/* this */) {


hello = hell; // here i want hell to hold the value of g




return env->NewStringUTF( hello.c_str());


}
Last edited on
An "activity" occurs only when you "exercise" it. Action is not data.
You want to modify some data in some action?

Copying g to hell is trivial:
hell = g;

Where and when you want that to happen is up to you.

Your three strings are in global scope. There is only one of each. Both of your functions can see them.
keskiverto: "Activity" is approximately what Android calls its processes. More properly, it's the user-facing part of a running application.

badboy1245: If this can be done, you should be able to do it from the Java side. Why are you trying to do it in native?
I want to read a file from java and be able to take the lines from the file and send it back to java to display in a text box. I know i can do that in java but i;m going to do some programing with the lines before i send them back.
Last edited on
So basically you just need a native function that accepts a string parameter from Java and returns a string value back to Java, right? It sounds like you don't need to do the send in native.
Yes, thats right, how can I do that?
Google "android jni return string". There's tons of documentation online.
Topic archived. No new replies allowed.