How to terminate android NDK (native activity) application programatically?
I have tried to call ANativeActivity_finish
(state->activity) from code when application request termination. This works, however my application cannot be restarted and it shows the following in LogCat:
W/ActivityManager( 238): Duplicate finish request for HistoryRecord
Everything seems to work p开发者_高级运维roperly when the user hit the back button, however I need to be able to issue the exit command from within my application. Any suggestion?
That's the way. I don't know how you're doing exactly, I guess that you do that call at the end of the code, then return from the android_main.
You have to ANativeActivity_finish()
and continue with the event loop until android_app->destroyRequested
. In your event handler, you'll find the appropriate APP_CMD_STOP
and APP_CMD_DESTROY
.
Doing it this way, now I have no problems. I used to do it with exit(0), but that was not the right thing.
精彩评论