Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 670
Steph Avatar asked Oct 06 '11 18:10

Steph


1 Answers

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.

like image 102
jcoll Avatar answered Oct 01 '22 09:10

jcoll