I'm trying to call from c>java, to open a URL (i.e. launch web browser). I have the code working in java to launch the url (it is a method of my main activity). It was working when I just did the call on the same thread, however, since I have made the call from another thread, it's broken.
I get the following errors: http://pastie.org/4696174
09-10 15:59:49.405: W/dalvikvm(31430): JNI WARNING: threadid=11 using env from threadid=1
09-10 15:59:49.405: E/dalvikvm(31430): JNI ERROR: env->self != thread-self (0x12988 vs. 0x200fb0); auto-correcting
09-10 15:59:49.405: W/dalvikvm(31430): JNI WARNING: threadid=11 using env from threadid=1
09-10 15:59:49.405: W/dalvikvm(31430): JNI WARNING: 0x41578910 is not a valid JNI reference
09-10 15:59:49.405: W/dalvikvm(31430): in Lcom/mrqwak/app/AppRenderer;.onDrawFrameN:()V (CallVoidMethodV)
09-10 15:59:49.415: I/dalvikvm(31430): "GLThread 876" prio=5 tid=11 RUNNABLE
09-10 15:59:49.415: I/dalvikvm(31430): | group="main" sCount=0 dsCount=0 obj=0x4157b270 self=0x200fb0
09-10 15:59:49.415: I/dalvikvm(31430): | sysTid=31443 nice=0 sched=0/0 cgrp=default handle=1986128
09-10 15:59:49.420: I/dalvikvm(31430): | schedstat=( 1035202257 457143963 4029 ) utm=80 stm=23 core=0
09-10 15:59:49.420: I/dalvikvm(31430): at com.mrqwak.app.AppRenderer.onDrawFrameN(Native Method)
09-10 15:59:49.420: I/dalvikvm(31430): at com.mrqwak.app.AppRenderer.onDrawFrame(AppActivity.java:289)
09-10 15:59:49.425: I/dalvikvm(31430): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1462)
09-10 15:59:49.425: I/dalvikvm(31430): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
09-10 15:59:49.425: E/dalvikvm(31430): VM aborting
09-10 15:59:49.430: A/libc(31430): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1)
Here is my c code: http://pastie.org/4696207
I call this from c>java, on main UI thread, as main activity is created:
JNIEnv* g_envApp = 0;
jobject g_objApp = 0;
jclass g_classApp = 0;
jmethodID g_methodOpenURL = 0;
JNIEXPORT void JNICALL Java_com_mrqwak_app_AppActivity_onCreateN(JNIEnv *env, jobject obj)
{
g_envApp = env;
g_objApp = obj;
g_classApp = env->GetObjectClass(obj);
if (g_classApp)
{
g_methodOpenURL = env->GetMethodID(g_classApp,"openURL","(Ljava/lang/String;)V");
}
}
I call this later, from c>java, NOT on main UI thead, when user presses a button to open a url:
extern JNIEnv* g_envApp;
extern jobject g_objApp;
extern jclass g_classApp;
extern jmethodID g_methodOpenURL;
void cHTTP::OpenURL(const char* psURL)
{
if (g_methodOpenURL)
{
jstring jstr = g_envApp->NewStringUTF(psURL);
g_envApp->CallVoidMethod(g_objApp,g_methodOpenURL,jstr);
}
}
Thanks,