Now, in android2.3, you can use the native_activity.h interface to implement a complete native activity. during use, make sure that the callback function cannot block the main UI thread. For more information, see <ndk_root>/platforms/Android-9/arch-arm/usr/include/Android/native_activity.h.
The native_app_glue static auxiliary Library provides callback for the event loop in another thread and is very easy to use. For details, refer to the native-activity sample program. The following describes how to use native_activity.h to implement the native activity program:
1. Create an android project in eclipse and create a JNI directory under the root directory of the project to store all local code.
2. Declare the local activity in the androidmanifest. xml file as follows:
<Manifest xmlns: Android = "http://schemas.android.com/apk/res/android"
Package = "com. example. native_activity"
Android: versioncode = "1"
Android: versionname = "1.0" type = "codeph" text = "/codeph">
<Uses-SDK Android: minsdkversion = "8"/>
<Application Android: Label = "@ string/app_name" Android: hascode = "false">
<Activity Android: Name = "android. App. nativeactivity"
Android: Label = "@ string/app_name"
Android: configchanges = "orientation | keyboardhidden">
<Meta-data Android: Name = "android. App. lib_name"
Android: value = "Native-activity"/>
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>
<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>
</Application>
</Manifest>
The main contents include:
-The Android: Name attribute of the activity tag must be set to Android. App. nativeactivity.
-The Android: Name attribute of the meta-data tag must be set to Android. App. lib_name. lib_name does not have the Lib prefix and. So Suffix of the module.
3. Create a file to implement the anativeactivity_oncreate () function for the activity to be called at startup. This function parameter is the anativeactivity struct pointer and contains the function pointer pointing to the callback function. These callback functions need to be programmed and assigned a value for anativeactivity> callbacks.
4/assign anativeactivity-> instance the data address to be used.
5. Implement other things that need to be done before the activity starts.
6. Implement other callback functions set in anativeactivity> Callbacks. For the call time of these callback functions, see the activity SDK documentation. Note that these implementations cannot be blocked, otherwise the main thread may receive ANR (the application has no response) errors at runtime.
7. Develop application functions
8. Create an android. mk file in the JNI directory to describe the compiler options of Local Code. This file is essentially part of the GNU make file. For example:
Local_path: = $ (call my-DIR)
Include $ (clear_vars)
Local_module: = my_native_module
Local_src_files: = my_native_code.c
Include $ (build_shared_library)
See the <ndk_root>/docs/ANDROID-MK.TXT file for how to create and what it means.
9/once the Android. mk file is available, you can use the "ndk-build" command to compile the code.
CD path/to/Project
<Ndk_root>/ndk-build
10. In the same way as regular applications, using antor eclipsewill automatically package the code in the jnivideo to the .apk file.