extern "C" void ANativeActivity_onCreate(ANativeActivity *activity, void * /*saved_state*/, size_t /*state_size*/)
{
- Msp::Android::MainThread *thread = new Msp::Android::MainThread(activity);
+ static Msp::Android::MainThread *thread = 0;
+ if(thread)
+ thread->attach_to_activity(activity);
+ else
+ thread = new Msp::Android::MainThread(activity);
thread->wait_for_app_created();
}
namespace Android {
MainThread::MainThread(ANativeActivity *a):
- activity(a),
starting_up(true)
{
+ attach_to_activity(a);
+ startup_mutex.lock();
+ launch();
+}
+
+void MainThread::attach_to_activity(ANativeActivity *a)
+{
+ activity = a;
+ activity->callbacks->onDestroy = &activity_destroyed;
activity->callbacks->onNativeWindowCreated = &native_window_created;
activity->callbacks->onNativeWindowResized = &native_window_resized;
activity->callbacks->onNativeWindowDestroyed = &native_window_destroyed;
activity->callbacks->onInputQueueCreated = &input_queue_created;
activity->callbacks->onInputQueueDestroyed = &input_queue_destroyed;
activity->instance = this;
-
- startup_mutex.lock();
-
- launch();
}
void MainThread::wait_for_app_created()
Msp::Android::ErrorLogger err_logger;
Msp::Application::run(1, argv, this, &app_created);
free(appname);
- ANativeActivity_finish(activity);
+ if(activity)
+ ANativeActivity_finish(activity);
}
void MainThread::app_created(void *data)
reinterpret_cast<MainThread *>(data)->resume_startup();
}
+void MainThread::activity_destroyed(ANativeActivity *activity)
+{
+ reinterpret_cast<MainThread *>(activity->instance)->activity = 0;
+}
+
void MainThread::native_window_created(ANativeActivity *activity, ANativeWindow *window)
{
reinterpret_cast<MainThread *>(activity->instance)->signal_native_window_created.emit(window);
public:
MainThread(ANativeActivity *);
+ void attach_to_activity(ANativeActivity *);
bool is_starting_up() const { return starting_up; }
void wait_for_app_created();
void resume_startup();
virtual void main();
static void app_created(void *);
+ static void activity_destroyed(ANativeActivity *);
static void native_window_created(ANativeActivity *, ANativeWindow *);
static void native_window_resized(ANativeActivity *, ANativeWindow *);
static void native_window_destroyed(ANativeActivity *, ANativeWindow *);