转:http://blog.csdn.net/xiruanliuwei/article/details/7560914

Android NDK为我们提供了两种方式来实现我们的native activity:

1、The native_activity.h header defines the native version of the NativeActivity class. It

contains the callback interface and data structures that you need to create your native

activity. Because the main thread of your application handles the callbacks, your callback

implementations must not be blocking. If they block, you might receive ANR (Application Not

Responding) errors because your main thread will be unresponsive until the callback returns.

Read the comments in the

<ndk_root>/platforms/android-9/arch-arm/usr/include/android/native_activity.h file for

more information.

2、The android_native_app_glue.h file defines a static helper library built on top of the

native_activity.h interface. It spawns another thread to handle things such as callbacks or

input events. This prevents any callbacks from blocking your main thread and adds some

flexibility in how you implement the callbacks, so you might find this programming model a

bit easier to implement.

The <ndk_root>/sources/android/native_app_glue/android_native_app_glue.c

source is also available to you, so you can modify the implementation if you need. Read the

comments in the <ndk_root>/sources/android/native_app_glue/android_native_app_glue.h

file for more information.

通过上面的描述,我们可以发现方式二会简单一些。在使用方式一实现native activity时,

需要注意在实现回调函数时,不要阻塞了main UI thread,否则会出现ANR。而方式二中,

则在一个新线程中创建一个事件循环执行回调函数,因此不会造成main UI thread阻塞。

Android NDK之二:创建NativeActivity的更多相关文章

  1. Ubuntu 14.04 Android 使用Maven二 创建自己的Mavenproject

    依据https://code.google.com/p/maven-android-plugin/wiki/GettingStarted 介绍,有两种方法能够创建Mavenproject. 第一种方法 ...

  2. Android Studio体验(二)--创建项目和Genymotion试用

    上周日已经体验了一把Android Studio顺便没事点了点其他功能,不过还是从自己创建项目开始说吧,首先我们要熟悉Android Studio中的Project 和 Module 两个概念.And ...

  3. windows系统上安装与使用Android NDK r8d(二)

    四.    在eclipse中集成c/c++开发环境    1. 装Eclipse的C/C++环境插件:CDT,这里选择在线安装.          首先登录http://www.eclipse.or ...

  4. 用Android NDK编译FFmpeg

    附(2018-01-06):     有一个将x264及lame等库集成进去了且基于android的ffmpeg的编译方法,地址参见:       https://github.com/writing ...

  5. 三、Android NDK编程预备之Java jni入门创建C/C++共享库

    转自: http://www.eoeandroid.com/thread-264971-1-1.html 应网友回复,答应在两天前要出一篇创建C/C++共享库的,但由于清明节假期,跟朋友出去游玩,丢手 ...

  6. Android NDK入门实例 计算斐波那契数列二生成.so库文件

    上一篇文章输生成了jni头文件,里面包含了本地C代码的信息,提供我们引用的C头文件.下面实现本地代码,再用ndk-build编译生成.so库文件.由于编译时要用到make和gcc,这里很多人是通过安装 ...

  7. Android NDK 开发(二) -- 从Hlello World学起【转】

    转载请注明出处:http://blog.csdn.net/allen315410/article/details/41805719  上篇文章讲述了Android NDK开发的一些基本概念,以及NDK ...

  8. 二、Android NDK编程预备之Java jni入门Hello World

    转自:  http://www.eoeandroid.com/forum.php?mod=viewthread&tid=264543&fromuid=588695 昨天已经简要介绍了J ...

  9. android NDK 实用学习(二)-java端对象成员赋值和获取对象成员值

    1,关于java端类及接口定义请参考: android NDK 实用学习-获取java端类及其类变量 2,对传过来的参数进行赋值: 对bool类型成员进行赋值  env->SetBooleanF ...

随机推荐

  1. leetcode74:二维矩阵搜索问题

    使用递归的方式解决,对于matrix,在左上角x,y,右下角xx,yy组成的区域内搜索target. mx=x和xx的中点,my=y和yy的中点 判断matrix[mx][my],如果它大于targe ...

  2. Windows系统使用vbs脚本或bat脚本强制杀死指定所有进程 vbs实现循环持续写入内容到vbs打开开的记事本 使用vbs、bat添加windows计划任务 使用cmd schtasks命令添加windows计划任务

    以下脚本windows7下成功运行过,脚本也可以windows计划任务程序一起组合使用 新建一个记事本文档粘贴下面代码后将新建的记事本文档重命名下面对应的脚本名就能使用了: 添加windows计划任务 ...

  3. 进阶之路(中级篇) - 015 串口控RGB三色灯

    本文由博主原创,如有不对之处请指明,转载请说明出处. /********************************* 代码功能:串口控RGB三色灯 使用函数: Serial.flush(); / ...

  4. 【转】25.windbg-!gle、g(错误码、g系列)

    !gle !gle 扩展显示当前线程的最后一个错误码.这个太好记了,getlasterror取首字母: <span style=:> !gle LastErrorValue: (Win32 ...

  5. log4j(五)——如何控制不同目的地的日志输出?

    一:测试环境与log4j(一)——为什么要使用log4j?一样,这里不再重述 二:老规矩,先来个栗子,然后再聊聊感受 import org.apache.log4j.*; import java.io ...

  6. 【Linux】进程优先级、进程nice值和%nice

    用top或者ps命令会输出PRI/PR.NI.%ni/%nice这三种指标值,这些到底是什么东西?先给出大概的解释如下: PRI :进程优先权,代表这个进程可被执行的优先级,其值越小,优先级就越高,越 ...

  7. golang学习笔记 --switch

    switch的例子: switch coinflip() { case "heads": heads++ case "tails": tails++ defau ...

  8. Android 热修复 Tinker接入及源码浅析

    一.概述 放了一个大长假,happy,先祝大家2017年笑口常开. 假期中一行代码没写,但是想着马上要上班了,赶紧写篇博客回顾下技能,于是便有了本文. 热修复这项技术,基本上已经成为项目比较重要的模块 ...

  9. matlab入门笔记(七):数据文件I/O

  10. Android 获取自带浏览器上网记录

    先是搜索了一下,在manifest里添加 <uses-permission android:name="com.android.browser.permission.READ_HIST ...