转: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. MATLAB 设置文件的相对路径

    加载文件使用命令:load(' 文件名 or 文件路径 ') 1.文件在当前路径下: 直接  load('session.mat') 2.文件在下一级路径下: 使用  load (' .\下一级路径的 ...

  2. 命令行修改MySQL数据库密码

    通过MySQL命令行来修改MySQL数据库的密码,下面就为您详细介绍如何使用MySQL命令行来修改密码. 格式:mysqladmin -u用户名 -p旧密码 password 新密码 1.给root加 ...

  3. golang项目结构

    一.概述 golang更新了环境变量,导致整个goproject的结构改变: [root@node175 goproject]# tree -L . ├── bin │   └── demo ├── ...

  4. Tensorflow 相关概念

    一.概述 人工智能:artificial intelligence 权重: weights 偏差:biases 图中包含输入( input).塑形( reshape). Relu 层( Relulay ...

  5. golang 学习 ---- channel

    把一个loop放在一个goroutine里跑,我们可以使用关键字go来定义并启动一个goroutine: package main import "fmt" func loop() ...

  6. JS遍历Table的所有单元格内容

    用JS去遍历Table的所有单元格中的内容,可以用如下JS代码实现: 这个方法的参数是唯一标识Table的id,用document对象的获取. function GetInfoFromTable(ta ...

  7. JQuery九大选择器

    九大选择器都是用来查找元素节点的.JQuery给我提供了九中类型的选择器. 1. 基本选择器  基本选择器是JQuery最常用的选择器,也是最简单的选择器,它通过元素id.class和标签名来查找DO ...

  8. T-SQL查询进阶--理解SQL Server中索引的概念,原理以及其他

    简介 在SQL Server中,索引是一种增强式的存在,这意味着,即使没有索引,SQL Server仍然可以实现应有的功能.但索引可以在大多数情况下大大提升查询性能,在OLAP中尤其明显.要完全理解索 ...

  9. 手把手带你画一个 时尚仪表盘 Android 自己定义View

    拿到美工效果图.咱们程序猿就得画得一模一样. 为了不被老板喷,仅仅能多练啊. 听说你认为前面几篇都so easy,那今天就带你做个相对照较复杂的. 转载请注明出处:http://blog.csdn.n ...

  10. 【转载】mysql配置模板(my-*.cnf)参数详细说明

    原文:https://yq.aliyun.com/ziliao/142086 mysql 性能优化分享,好文章: http://www.jb51.net/article/28363.htm mysql ...