1

ネイティブ アクティビティを終了する適切な方法は何ですか? つまり、android_main機能を終了するにはどうすればよいかということです。何もしないと、プログラムがハングし、最終的にデバイスが終了します。呼び出すとexit(0)終了しますが、正しくクリーンアップされていないことを示すダンプがログ ファイルに出力されます。

では、アプリケーションを正しく終了するにはどうすればよいですか?

編集:私は純粋に C++ でネイティブ アクティビティを作成しています。android_mainルーチンに戻る/完了する方法について質問しています。このプロジェクトには Java コードありません。

ログの失敗の上部のスニペット:

V/threaded_app( 5419): NativeWindowDestroyed: 0x29c490 -- 0x29d788
I/DEBUG   ( 1055): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   ( 1055): Build fingerprint: 'LENOVO/IdeaPad_Tablet_A1_07/A1_07:2.3.4/GRJ22/eng.user.20120209.100319:user/release-keys'
I/DEBUG   ( 1055): pid: 5419, tid: 5427  >>> eu.eversystems.sample <<<
I/DEBUG   ( 1055): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000024
I/DEBUG   ( 1055):  r0 0029d788  r1 463ddb64  r2 5f776e64  r3 00000000
4

3 に答える 3

1

私はこれを試したことはありませんがANativeActivity_finish()、ネイティブ アクティビティ ポインターを呼び出すとうまくいくと思います。

于 2012-08-29T10:29:37.330 に答える
0

NDKのnative-activityの例を見ると、android_mainはvoid関数であるため、「終了」するときに「戻る」だけで済みます。

ただし、android_mainから戻る方法/タイミングに注意する必要があります。Android上のアプリは、通常の状況では実際には「終了」しません。それらはフォアグラウンドに出入りします。当然、プロセスがバックグラウンドにあり、OSデバイスが不要になった場合は、おっしゃるようにプロセスが終了します。この場合、android_native_app_glueライブラリの「destroyRequested」フィールドが設定されていることを期待します。これにより、android_mainからの戻りがトリガーされます。これにより、アプリケーションを正常に終了できます。

他のすべての場合では、アプリがそれ自体を見つける可能性のあるさまざまな状態を尊重するようにしたいだけです。

すなわち:

/**
 * 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,

サンプルコードは次のとおりです。

http://developer.android.com/reference/android/app/NativeActivity.html

于 2012-10-09T06:14:06.120 に答える
-1

使えます

android:noHistory="true" 

すべてのアクティビティのマニフェストで:)そして

finish() 

あなたの現在の活動..完了です! :)それが役立つことを願っています

于 2012-08-17T11:05:21.160 に答える