Steph
Steph

Reputation: 1761

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 properly when the user hit the back button, however I need to be able to issue the exit command from within my application. Any suggestion?

Upvotes: 9

Views: 5352

Answers (1)

jcoll
jcoll

Reputation: 790

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.

Upvotes: 7

Related Questions