]> git.tdb.fi Git - libs/core.git/commitdiff
Terminate the process when the application has finished running
authorMikko Rasa <tdb@tdb.fi>
Thu, 13 Nov 2014 20:44:51 +0000 (22:44 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 13 Nov 2014 20:44:51 +0000 (22:44 +0200)
Otherwise the OS may try to start the activity again in the same process,
which doesn't work because of Application::run semantics.

source/core/android/mainthread.cpp
source/core/android/mainthread.h

index 473379bd71ce373c4e8e8829d4a00ece43ff3c57..d394f838bcd497495255dc14296313f546a7813f 100644 (file)
@@ -1,4 +1,5 @@
 #include <cstring>
+#include <cstdlib>
 #include <msp/fs/dir.h>
 #include <msp/fs/path.h>
 #include <msp/fs/utils.h>
@@ -58,7 +59,12 @@ void MainThread::main()
        Msp::Application::run(1, argv, this, &app_created);
        free(appname);
        if(activity)
+       {
+               activity->callbacks->onDestroy = &end_process;
                ANativeActivity_finish(activity);
+       }
+       else
+               end_process(0);
 }
 
 void MainThread::app_created(void *data)
@@ -96,5 +102,10 @@ void MainThread::input_queue_destroyed(ANativeActivity *activity, AInputQueue *q
        reinterpret_cast<MainThread *>(activity->instance)->signal_input_queue_destroyed.emit(queue);
 }
 
+void MainThread::end_process(ANativeActivity *)
+{
+       exit(0);
+}
+
 } // namespace Android
 } // namespace Msp
index 4bac952bc149bd839b1815be03981d6ff130baea..09f907f174a30862e9f970cd005590a0a9b12ece 100644 (file)
@@ -47,6 +47,7 @@ private:
        static void native_window_destroyed(ANativeActivity *, ANativeWindow *);
        static void input_queue_created(ANativeActivity *, AInputQueue *);
        static void input_queue_destroyed(ANativeActivity *, AInputQueue *);
+       static void end_process(ANativeActivity *);
 };
 
 } // namespace Android