2011-03-18 3 views
7

나는 자바 코드로로드하는 두 개의 라이브러리 (.so)를 가지고있다.네이티브 활동을 사용하는 방법? 전통적인 활동과 결합 될 수 있습니까?

그러나 Java (활동) < -> C++ (. so 파일) 호출이 필요한 몇 가지 특정 작업이 있습니다.

네이티브 액티비티를 사용하여 해당 기능의 일부를 구현할 수 있습니까? 네이티브 액티비티는 전통적인 액티비티에 추가적으로 필요한 것입니까, 아니면 선택해야합니까? 어떤 액티비티를 사용할 것입니까?

[편집] native activity

안드로이드 NDK/소스/안드로이드/native_app_glue/android_native_app_glue.h

에 의해 네이티브 코드로 처리 할 수있는 이벤트 집합이

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++에서이를 처리합니다. 그러나 자바에서 이벤트를 처리 한 후에 호출해야하는 코드도 있습니다.

질문은 ... 내 활동의 기본 버전 (기본 인터페이스)을 가질 수 있으며, 동일한 이벤트에서 이와 동일한 활동을 수행하는 데 도움이 될 수 있습니까?

+0

@noisy 네 문제는 "두 개의 기본 라이브러리를로드 할 수 없다"입니다. 제가 맞습니까? – 100rabh

답변

3

두 가지 버전의 코드가 하나만있을 수 있습니다.

  • 어떻게 매니페스트에 지정 하시겠습니까? Google에서 제공하는 샘플에서

  • 메인의 의견은 매우 명시 적이다 :

그것은 다른 일을 입력 이벤트를 수신하기 위해 자체 이벤트 루프와 함께, 자신의 스레드에서 실행

네이티브 동작은 루프 while(1) {...}의 모든 이벤트를 처리합니다. 자바와 네이티브 이벤트를 혼합하는 것은 불가능합니다.

IMHO, 기본 활동을 사용하는 주된 이유는 UI입니다. C++에서 이미 완벽하게 기능하는 UI를 사용하고 있다면, 더 쉽게 네이티브 액티비티를 사용할 수 있습니다. 안드로이드가 다른 자바 활동을 추가 할 수 있도록 앱을 맞춤 설정할 수 있습니다 (android:hasCode="TRUE"를 매니페스트에 넣어야합니다!). 다른 경우, 자바 액티비티를 사용하면 Google UI를 완벽하게 사용할 수 있으며 필요한 경우 네이티브 라이브러리를 호출 할 수 있습니다. 당신에 대해

성능 문제는, 당신이 말할 때 : http://developer.android.com/guide/practices/design/performance.html#native_methods

:

내가 그것을이 살펴보고 기본 활동

를 통해 C++에서이 문제를 처리하기 위해 더 좋을 것 같아요 희망이 도움이!

관련 문제