Important: Please read the Qt Code of Conduct -

Android: QtService doesn't call onDestroy after calling stopSelf

  • I have problem to close my service on Android. After calling stopSelf() in the service, the function onDestroy gets never called. I made a minimal example based on the this guide.

    And I modified the code like this:

    #include <QAndroidService>
    #include <QtAndroid>
    #include "rep_pingpong_source.h"
    class PingPong : public PingPongSource {
    public slots:
        // PingPongSource interface
        void ping(const QString &msg) override {
            emit pong(msg + " from server");
            if (msg == "Quit") {
    int main(int argc, char *argv[])
        QAndroidService app(argc, argv);
        QRemoteObjectHost srcNode(QUrl(QStringLiteral("local:replica")));
        PingPong pingPongServer;
        return app.exec();

    import android.content.Context;
    import android.content.Intent;
    import android.util.Log;
    public class MyService extends QtService
        public static void startMyService(Context ctx) {
            ctx.startService(new Intent(ctx, MyService.class));
        public void onDestroy() {
            Log.d("Service Test", "Called onDestroy");
        public void quit() {

    The log message is not printed so I guess the function is not called. But the process is terminated. In my case the process is not even terminated. I guess it is because some receivers ore not unregistered because the onDestroy function is not executed.

Log in to reply