QtCS2015 AndroidServices

From Qt Wiki
Jump to: navigation, search

Services

We want to make it possible to implement Android services using Qt.

Definitions:

Services: anything that runs in the background

Activity: something that has a GUI

Android applications may contain both service and activity. Qt currently only supports one activity. We do not want to support more than one activity in a Qt application, but we want to be able to support one service in addition to one activity.

Two possible strategies:


  1. Separate processes for the activity and service
    1. IPC communication
    2. intents
  2. Something new
    1. allowing the same process to run both in GUI mode and service mode


Option 2 requires several changes in Qt:

  • Long standing discussion about getting rid of main() and introducing QT_MAIN entry point
    • Qt 6 material, but we can introduce the concept just for Android in 5.x
  • Which thread do we run the QGuiApplication in? What if the service starts first?
    • We need to start two threads when service starts first: both the service and GUI thread


Conclusion: we chose option 1: the service runs in separate process from the activity. Android will normally run both in the same process, but there is an option in the manifest to run them separately.

Two sub-options:

  • Service and activity implemented in completely different apps
    • Needs two entries in the app store, causing confusion
  • both service and activity in same app
    • EITHER: two entry points in same Qt code -- each entry point instantiates its own QCoreApplication/QGuiApplication
    • OR: entry points in separate libs -- Qt chooses different lib to load when run as activity or service

Conclusion: We chose both service and activity in same app, and the same compilation unit. It is easier to build and deploy. This means that we also introduce macros for defining entry points, which will replace main() for apps that implement services.

Should this be cross-platform API?

Other platforms have similar concepts, so it would be good to have a cross-platform API for this.

Conclusion: We do it in QtAndroidExtras for the first iteration, and then we can build a cross-platform solution later.


Tooling changes

Adding support for a service entry point requires changing the template, i.e. the Java code that is copied into each Qt application.

Since this functionality will be added in QtAndroidExtras, we need to change the tools so that modules other than QtBase can add to the templates. This will also be useful for other cases.


Proper intents support for Qt

With service and activity in separate processes, Android intents is a good way to communicate between them. While it is possible to write the Java code yourself, it would be good to have a proper Qt API.

There is something private API in the NFC code in 5.6. We may want to take that code and make it public.