Never mind. These problems arose when using the NativeActivity sample (using android_main() etc.) as a basis of how to do an OpenGL Android app.
I've switched to using a more normal "extends activity" main class as in the SanAngeles sample, and now these problems (and others) do not occur anymore.
On Saturday, September 22, 2012 10:40:31 PM UTC-3, Aidan M wrote:
Hi there,
I'm trying to get the users contacts using a jni call:
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
However this requires a class with "extends Activity". I can get a method in a normal java class to run fine, but when I try to add "extends activity" I start to get looper.prepare not called etc. messages/crashes, and no amount of runnables, or handlers, attachtouithread etc. has helped so far.
So is there any other way I can call the getContentResolver() in a non-activity java class?
p.s. I use the following code to get java methods:
jclass activityClass = env->FindClass("android/app/NativeActivity");
jmethodID getClassLoader = env->GetMethodID(activityClass,"getClassLoader", "()Ljava/lang/ClassLoader;");
jobject cls = env->CallObjectMethod(activity->clazz, getClassLoader);
jclass classLoader = env->FindClass("java/lang/ClassLoader");
jmethodID findClass = env->GetMethodID(classLoader, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
jstring strClassName = env->NewStringUTF(class_str);
jclass classIWant = (jclass)env->CallObjectMethod(cls, findClass, strClassName);
jci->method_id = env->GetMethodID(classIWant, method_str, method_format);