lib/android: if there is no activities, run UI code on the caller thread
authorAlexis Laferrière <alexis.laf@xymus.net>
Fri, 11 Mar 2016 18:55:55 +0000 (13:55 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Sun, 13 Mar 2016 14:23:24 +0000 (10:23 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/android/http_request.nit

index d7427c3..2b9fd14 100644 (file)
@@ -30,7 +30,15 @@ in "Java" `{
 `}
 
 redef class App
-       redef fun run_on_ui_thread(task) do app.native_activity.run_on_ui_thread task
+       redef fun run_on_ui_thread(task)
+       do
+               if app.activities.not_empty then
+                       app.native_activity.run_on_ui_thread task
+               else
+                       # There is no UI, it must be a service, run on the caller thread
+                       task.main
+               end
+       end
 end
 
 redef class Text