android2.3 gps上传数据后重启或是 JNIEnv* env = AndroidRuntime::getJNIEnv(); return == NULL
来源:互联网 发布:怎样注册免费域名 编辑:程序博客网 时间:2024/05/16 08:48
转载时请注明出处和作者文章出处:http://blog.csdn.net/lbmygf/archive/2011/06/16/6548086.aspx
作者:曼云-->孤峰
从android2.2 GPS到android2.3 GPS 结构上有些变化,这里主要说如题所讲的问题。(文件都在硬件抽象层自己找,呵呵)
对比一下2.2和2.3的回调函数发现2.3多了很多,其中有个很重要,(gps.h)
/** Callback for creating a thread that can call into the Java framework code.
* This must be used to create any threads that report events up to the framework.
*/
typedef pthread_t (* gps_create_thread)(const char* name, void (*start)(void *), void* arg);
就是这个了,看看他的解释This must be used 必须的用,不用不行,不用你就会出现标题中的问题,我看开始时也没看这些,郁闷了些
时间。
下面讲讲怎么用她:
在2.2时 static void gps_state_init( GpsState* state ) 函数中 (gps_qemu.c)
有 if ( pthread_create( &state->thread, NULL, gps_state_thread, state ) != 0 ) {
LOGE("could not create gps thread: %s", strerror(errno));
goto Fail;
}
这样一句对波,到2.3的时候 这句话就不行了,要退休了,2.2到2.3系统还是做了很多优化的,这个就是了,2.2的系统会轮询你有没有
创建线程,2.3不会了,你不告诉他,他就不知道,JNIEnv* env = AndroidRuntime::getJNIEnv();这句回去获取创建线程,不用回
调函数把线程传上去,上层不知道有这个线程,JNIEnv* env == NULL ,所以你把数据传上去时就出问题了,我遇到的现象是系统不
断重启,所以你要改。
首先:
static int
qemu_gps_init(GpsCallbacks* callbacks)
{
GpsState* s = _gps_state;
s->callbacks = *callbacks;
if (!s->init)
gps_state_init(s);
return 0;
}
把那 s->callbacks = *callbacks;放到gps_state_init(s);前面去
为什么呢? 你再 gps_state_init(s);中要用到回调函数上传线程啊,你不先给个接口给他,他怎么传啊。
然后:
就是把
if ( pthread_create( &state->thread, NULL, gps_state_thread, state ) != 0 ) {
LOGE("could not create gps thread: %s", strerror(errno));
goto Fail;
}
这句换成
state->callbacks.create_thread_cb("qemu_gps", gps_state_thread, state);
第一个参数"qemu_gps"好像没啥特定意义,自己随便,没研究出来。其他的因该都知道哈。
恩,问题解决
- android2.3 gps上传数据后重启或是 JNIEnv* env = AndroidRuntime::getJNIEnv(); return == NULL
- Android:GPS定位 Location == null
- [android2.3]GPS启动流程及数据流向分析
- [android2.3]GPS启动流程及数据流向分析
- [android2.3]GPS启动流程及数据流向分析
- porting gps to android2.3
- android2.3 gps 架构流程
- porting gps to android2.3
- GPS 研究(Android2.3)
- jint* intArr = (*env)->GetIntArrayElements(env,arr,1);报错
- GPS 研究一 (Android2.3)
- GPS 研究一 (Android2.3)
- GPS 研究三 (android2.3__gingerbread)
- porting gps to android2.3 (一)
- android2.3 GPS HAL 移植实战
- jni 新线程使用JNIEnv *env
- android2.3 gps 调用流程以及与android2.2 gps的一些区别
- Android之ndk中JNIENV env->NewStringUTF (*env)->NewStringUTF
- SVN使用小记
- How do I install PECL uploadprogress library
- flash 声音设置
- 成功用jdbc 实现从oracle 读取出一个时间间隔的数据
- 在 .NET 中调用SAP RFC 接口 VS03和VS08连接SAP
- android2.3 gps上传数据后重启或是 JNIEnv* env = AndroidRuntime::getJNIEnv(); return == NULL
- joomla1.5与Phpbb3的桥接
- WEB项目服务器启动后内存开辟空间存放共享信息方法(原创)
- oracle 日期常用函數 (SYSDATE、日期格式) 收藏
- 全变分,转载
- hdu 2069(另类版母函数)
- 自己的第一个C++定时器
- iphone NSString与NSMutableString的区别
- oracle 存储过程的基本语法 收藏