Some API like requesting user location, needs to be called in the main UI thread. How to send a message from a working thread to main UI thread? Here is an example:
Showing posts with label android. Show all posts
Showing posts with label android. Show all posts
2018/12/02
2018/11/18
2018/11/16
Android UI, Line Layout in Constrait Layout
This example show 6 line layout containers in a constraint layout, looks like below:
The layout XML is like
The layout XML is like
2011/11/22
Get Thread JNIEnv
This is an example shows how:
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) { cached_jvm = jvm; /* cache the JavaVM pointer */ return JNI_VERSION_1_2; } static void Some_Function() { (*cached_jvm)->AttachCurrentThread(cached_jvm, &env, NULL); (*env)->MonitorEnter(env, callbackInst); jclass cls = (*env)->GetObjectClass(env, callbackInst); jmethodID id = (*env)->GetMethodID(env, cls, "callback", "(I)V"); (*env)->CallVoidMethod(env, callbackInst, id, (int)l); (*env)->MonitorExit(env, callbackInst); }
2011/08/15
CheckJNI of NewStringUTF
In file Check dalvik/vm/checkjni.c
This is the function which check the input string of NewStringUTF is a valid UTF8 or not.
If not valid, the check function will abort the VM.
That caused our application got crashed when there are some mal-formated UTF8 string.
This is the function which check the input string of NewStringUTF is a valid UTF8 or not.
If not valid, the check function will abort the VM.
That caused our application got crashed when there are some mal-formated UTF8 string.
/* * Verify that "bytes" points to valid "modified UTF-8" data. */ static void checkUtfString(JNIEnv* env, const char* bytes, bool nullOk, const char* func) { const char* origBytes = bytes; if (bytes == NULL) { if (!nullOk) { LOGW("JNI WARNING: unexpectedly null UTF string\n"); goto fail; } return; } while (*bytes != '\0') { u1 utf8 = *(bytes++); // Switch on the high four bits. switch (utf8 >> 4) { case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07: { // Bit pattern 0xxx. No need for any extra bytes. break; } case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0f: { /* * Bit pattern 10xx or 1111, which are illegal start bytes. * Note: 1111 is valid for normal UTF-8, but not the * modified UTF-8 used here. */ LOGW("JNI WARNING: illegal start byte 0x%x\n", utf8); goto fail; } case 0x0e: { // Bit pattern 1110, so there are two additional bytes. utf8 = *(bytes++); if ((utf8 & 0xc0) != 0x80) { LOGW("JNI WARNING: illegal continuation byte 0x%x\n", utf8); goto fail; } // Fall through to take care of the final byte. } case 0x0c: case 0x0d: { // Bit pattern 110x, so there is one additional byte. utf8 = *(bytes++); if ((utf8 & 0xc0) != 0x80) { LOGW("JNI WARNING: illegal continuation byte 0x%x\n", utf8); goto fail; } break; } } } return; fail: LOGW(" string: '%s'\n", origBytes); showLocation(dvmGetCurrentJNIMethod(), func); abortMaybe(); }
Android CheckJNI
CheckJNI can catch a number of common errors.
A simple way to enable or disable JNI:
adb remount
adb pull /system/build.prop .
delete or add line ro.kernel.android.checkjni=1
adb push build.prop /system/.
adb shell reboot
Reference:
http://android-developers.blogspot.com/2011/07/debugging-android-jni-with-checkjni.html
A simple way to enable or disable JNI:
adb remount
adb pull /system/build.prop .
delete or add line ro.kernel.android.checkjni=1
adb push build.prop /system/.
adb shell reboot
Reference:
http://android-developers.blogspot.com/2011/07/debugging-android-jni-with-checkjni.html
Subscribe to:
Posts (Atom)
Post Code on Blogger
Simplest way to post code to blogger for me: <pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black;overflow-x:...
-
Explain There is not interrupt PIN for PCIe interrupt. When device wants to raise an interrupt, an interrupt message is sent to host via ...
-
Configure Space Addressing One of the major improvements the PCI Local Bus had over other I/O architectures was its configuration mechanism...
-
Example goes here: String url3 = " https://ajax.googleapis.com/ajax/services/search/news?v=1.0&q=barack%20obama " ; JsonpR...
