Android NDK之二:创建NativeActivity
来源:互联网 发布:怎么招募淘宝客 编辑:程序博客网 时间:2024/05/16 08:41
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阻塞。
下面分别以上面介绍的两种方式实现我们的native activity:
方式一:
方式二:
- Android NDK之二:创建NativeActivity
- Ogre3d 之使用 Android NativeActivity
- Android NDK之纯 C 或 C++ 安卓工程NativeActivity
- Android ndk 之二
- Android ndk 之二
- NDK: NativeActivity原理
- “暗隐间谍”--利用NDK NativeActivity技术实现Android加固
- android,NativeActivity使用
- Android NativeActivity原理
- Android-NDK开发之基础--Android NDK开发技巧二
- Android-NDK开发之基础--Android NDK开发技巧二
- Android NDK学习之二. ndk-build使用
- 创建NativeActivity项目(Eclipse)
- Android NDK 开发之(二) 牛刀小试
- Android NDK 开发之(二) 牛刀小试
- android ndk开发之二 认识jni
- NDK-Android项目创建
- android ndk 创建过程
- DENX U-Boot及Linux使用手册
- DirectX9 SDK Samples(15) OptimizedMesh Sample
- iphone---MyfistLabel
- java新手求职深圳
- flex4.5 spark datagrid itemrenderer
- Android NDK之二:创建NativeActivity
- TCP循环服务器 UDP循环服务器 TCP并发服务器
- 论文阅读——R树
- 【算法入门】深度优先搜索(DFS)
- 使用Ext Form自动绑定Html中的Form元素
- 史上最强第2代智能CPU核芯显卡性能测试
- 【Android初学者】之Dialog 汇总
- 论文预读——GIS笔记
- RTSP协议格式(转)