Mar 9, 2018 at 12:15pm UTC
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 Mar 9, 2018 at 12:17pm UTC
Mar 9, 2018 at 12:43pm UTC
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.
Mar 9, 2018 at 2:20pm UTC
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?
Mar 9, 2018 at 3:18pm UTC
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 Mar 9, 2018 at 3:52pm UTC
Mar 9, 2018 at 4:04pm UTC
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.
Mar 9, 2018 at 5:05pm UTC
Yes, thats right, how can I do that?
Mar 9, 2018 at 7:22pm UTC
Google "android jni return string". There's tons of documentation online.