摘要: // 重启应用 public void restartApp() { Intent intent = new Intent(); // 参数1:包名,参数2:程序入口的activity intent.setClassName(getPackageName(), "包名"); PendingIntent restartIntent = PendingIntent.getActivity( getApplicationContext(), 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK); AlarmManager mgr = (Alarm.. 阅读全文
posted @ 2014-03-19 15:36 porter_代码工作者 阅读(1404) 评论(0) 推荐(0)
摘要: 时常在cpp的代码之中看到这样的代码:#ifdef __cplusplusextern "C" {#endif//一段代码#ifdef __cplusplus}#endif 这样的代码到底是什么意思呢?首先,__cplusplus是cpp中的自定义宏,那么定义了这个宏的话表示这是一段cpp的代码,也就是说,上面的代码的含义是:如果这是一段cpp的代码,那么加入extern "C"{和}处理其中的代码。 要明白为何使用extern "C",还得从cpp中对函数的重载处理开始说起。在c++中,为了支持重载机制,在编译生成的汇编码中,要对函 阅读全文
posted @ 2014-03-19 14:58 porter_代码工作者 阅读(400) 评论(0) 推荐(0)
摘要: STL的排序太坑了,尤其是在VS2010上重载sort函数的第三个比较参数的时候。invalid operator #include#include#includeusing namespace std;struct Node{ int x; int y;};bool Comp(Node &a,Node &b){ if(a.x==b.x) return b.y>a.y; else return a.x>b.x;}vector node;int main(){ srand((unsigned int)time(0)); for(int i... 阅读全文
posted @ 2014-03-11 14:24 porter_代码工作者 阅读(334) 评论(0) 推荐(0)
摘要: 经常遇到到问题: 问题1. 忘记delete local reference。带New到方法(如:NewByteArray)这样到方法比较好辨认,需要手动调用DeleteLocalRef()来释放(返回值除外)。比较特殊的一个方法是:GetByteArrayELement必须要调用ReleaseByteArrayElements进行释放。当然如果你只是取bytearray中到byte,那么完全可以用GetByteArrayRegion实现。 问题2. 没有NewGlobalRef。 在不同线程调用java方法,需要保存jobject对象,这时需要对jobject对象做全局引用,否则会失效。.. 阅读全文
posted @ 2014-03-03 15:20 porter_代码工作者 阅读(637) 评论(0) 推荐(0)
摘要: 一、概述 JNI编程和Linux上的C/C++编程还是挺相似的,每次java调用JNI中的函数时都会传入有关JVM的一些参数(如JNIEnv,jobject),每次JNI回调java中的方法时都要通过JVM的有关参数来实现,当在JNI中涉及到多线程的话还是有一些不一样的地方,就是要在子线程函数里使用AttachCurrentThread()和DetachCurrentThread()这两个函数,在这两个函数之间加入回调java方法所需要的代码。 #include#include#include#include#include#include#define LOGI(...) ((void... 阅读全文
posted @ 2014-03-03 15:20 porter_代码工作者 阅读(1148) 评论(0) 推荐(0)
摘要: A JNI interface pointer (JNIEnv*) is passed as an argument for each native function mapped to a Java method, allowing for interaction with the JNI environment within the native method.This JNI interface pointer can be stored, but remains valid only in the current thread.Other threads must first call 阅读全文
posted @ 2014-03-03 14:51 porter_代码工作者 阅读(2283) 评论(0) 推荐(0)
摘要: // Note://int x = a[0].GetInt(); // Error: operator[ is ambiguous, as 0 also mean a null pointer of const char* type.int y = a[SizeType(0)].GetInt(); // Cast to SizeType will work.int z = a[0u].GetInt(); // This works too.0u = SizeType(0)Json::Value作为数组时,读取0位置时,出现错误:Use of overload... 阅读全文
posted @ 2014-03-03 14:11 porter_代码工作者 阅读(1527) 评论(0) 推荐(0)
摘要: android调试工具addr2line使用:1.将ndk中的arm-linux-androideabi-addr2line可执行文件的路径加入配置文件~/.bashrc中,例如:export PATH=$PATH:~/dlna/android-ndk-r6b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin2.使配置生效:source ~/.bashrc3.使用工具。例如:arm-linux-androideabi-addr2line -C -f -e ~/workspace/DLNA/libs/armeabi/lib 阅读全文
posted @ 2014-02-26 15:55 porter_代码工作者 阅读(2994) 评论(0) 推荐(0)
摘要: ---视频http://www.lanou3g.com/newslist.php?cid=7http://edu.51cto.com/lesson/id-15489.htmlhttp://www.microoh.com/04/02/25/25/---对比学习http://blog.csdn.net/totogo2010/article/details/7632384 阅读全文
posted @ 2014-02-24 23:10 porter_代码工作者 阅读(226) 评论(0) 推荐(0)
摘要: HandlerThread继承于Thread,所以它本质就是个Thread。HandlerThread类用于方便的创建一个含有looper的线程类,looper用来创建handler类。我们一般不创建looper对象,直接调用HandlerThread即可。HandlerThread本身实现了循环处理消息的功能,不用再直接调用Looper.prepare()和Looper.loop()方法。与普通Thread的差别就在于,它有个Looper成员变量。这个Looper其实就是对消息队列以及队列处理逻辑的封装,简单说就是消息队列+消息循环。使用HandlerThread步骤如下://步骤1:创新H 阅读全文
posted @ 2013-06-18 15:53 porter_代码工作者 阅读(310) 评论(0) 推荐(0)