Android 如何使用本机活动?它能与传统活动结合起来吗?
我有两个库(.so),我用java代码加载它们 但是,有一些特定的操作需要Java(活动)C++(.so文件)调用 我可以使用本机活动来实现这些功能的一部分吗?本土活动是传统活动之外的活动吗?还是我必须选择,我将使用哪种类型的活动 [编辑] 有一组事件可以由 android ndk/sources/android/native_app_glue/android_native_app_glue.hAndroid 如何使用本机活动?它能与传统活动结合起来吗?,android,android-activity,native,Android,Android Activity,Native,我有两个库(.so),我用java代码加载它们 但是,有一些特定的操作需要Java(活动)C++(.so文件)调用 我可以使用本机活动来实现这些功能的一部分吗?本土活动是传统活动之外的活动吗?还是我必须选择,我将使用哪种类型的活动 [编辑] 有一组事件可以由 android ndk/sources/android/native_app_glue/android_native_app_glue.h enum { /** * Command from main thread: th
enum {
/**
* Command from main thread: the AInputQueue has changed. Upon processing
* this command, android_app->inputQueue will be updated to the new queue
* (or NULL).
*/
APP_CMD_INPUT_CHANGED,
/**
* Command from main thread: a new ANativeWindow is ready for use. Upon
* receiving this command, android_app->window will contain the new window
* surface.
*/
APP_CMD_INIT_WINDOW,
/**
* Command from main thread: the existing ANativeWindow needs to be
* terminated. Upon receiving this command, android_app->window still
* contains the existing window; after calling android_app_exec_cmd
* it will be set to NULL.
*/
APP_CMD_TERM_WINDOW,
/**
* Command from main thread: the current ANativeWindow has been resized.
* Please redraw with its new size.
*/
APP_CMD_WINDOW_RESIZED,
/**
* Command from main thread: the system needs that the current ANativeWindow
* be redrawn. You should redraw the window before handing this to
* android_app_exec_cmd() in order to avoid transient drawing glitches.
*/
APP_CMD_WINDOW_REDRAW_NEEDED,
/**
* Command from main thread: the content area of the window has changed,
* such as from the soft input window being shown or hidden. You can
* find the new content rect in android_app::contentRect.
*/
APP_CMD_CONTENT_RECT_CHANGED,
/**
* Command from main thread: the app's activity window has gained
* input focus.
*/
APP_CMD_GAINED_FOCUS,
/**
* Command from main thread: the app's activity window has lost
* input focus.
*/
APP_CMD_LOST_FOCUS,
/**
* Command from main thread: the current device configuration has changed.
*/
APP_CMD_CONFIG_CHANGED,
/**
* Command from main thread: the system is running low on memory.
* Try to reduce your memory use.
*/
APP_CMD_LOW_MEMORY,
/**
* Command from main thread: the app's activity has been started.
*/
APP_CMD_START,
/**
* Command from main thread: the app's activity has been resumed.
*/
APP_CMD_RESUME,
/**
* Command from main thread: the app should generate a new saved state
* for itself, to restore from later if needed. If you have saved state,
* allocate it with malloc and place it in android_app.savedState with
* the size in android_app.savedStateSize. The will be freed for you
* later.
*/
APP_CMD_SAVE_STATE,
/**
* Command from main thread: the app's activity has been paused.
*/
APP_CMD_PAUSE,
/**
* Command from main thread: the app's activity has been stopped.
*/
APP_CMD_STOP,
/**
* Command from main thread: the app's activity is being destroyed,
* and waiting for the app thread to clean up and exit before proceeding.
*/
APP_CMD_DESTROY,
};
<>因为我知道我的代码的一部分(应该在特定事件之后调用)是用C++编写的,我认为最好是通过本地活动在C++中处理这个问题。然而,我也有一些代码,它们必须在Java中处理事件之后调用
问题是。。。我可以拥有我的活动的本机版本(本机接口)吗?它可以帮助我处理一些事件,同时我可以拥有同一活动的传统java接口吗?我会回答,一个活动不能有两个版本的代码
- 您将如何在您的清单中指定
- 在谷歌提供的示例中,main的评论非常明确:
中的所有事件,而(1){…}
。混合使用Java和本机事件是不可能的
依我看,使用本机活动的主要原因是UI。如果您已经在C++中拥有了完全功能的UI,那么对于您来说,使用本地活动更容易和更便携。您仍然可以为android自定义应用程序并添加其他java活动(不要忘记将android:hasCode=“TRUE”
放在清单中!)。在另一种情况下,使用java活动可以让您充分使用GoogleUI,并在需要时调用本机库
关于你的绩效问题,当你说:
<>我想最好是通过本地活动在C++中处理这个问题。
看看这个:
希望这有帮助 据我所知,您的问题是“无法加载两个本机库”,对吗?