• Android NDK之二:创建NativeActivity


    转: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阻塞。

  • 相关阅读:
    最短路径 一 Dijkstra 模板(O(n^2))
    【转】STL中的set容器的一点总结
    水题 等差数列HDU 5400 Arithmetic Sequence
    贪心+等价转化 HDU 1489
    POJ 3258 最小值最大化 二分搜索
    【转】二分查找算法学习札记
    UVa 714 Copying books 贪心+二分 最大值最小化
    湖南程序设计竞赛赛题总结 XTU 1237 Magic Triangle(计算几何)
    并查集基础 模板题 hdu1232 畅通工程
    数论 最简分数 Farey序列求最简分数+POJ3374
  • 原文地址:https://www.cnblogs.com/liulipeng/p/3524423.html
Copyright © 2020-2023  润新知