Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Android: QtService doesn't call onDestroy after calling stopSelf
Forum Updated to NodeBB v4.3 + New Features

Android: QtService doesn't call onDestroy after calling stopSelf

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 538 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vlada
    wrote on last edited by
    #1

    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:
    server.cpp

    #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") {
                QtAndroid::androidService().callMethod<void>("quit");
            }
        }
    };
    
    int main(int argc, char *argv[])
    {
        QAndroidService app(argc, argv);
    
        QRemoteObjectHost srcNode(QUrl(QStringLiteral("local:replica")));
        PingPong pingPongServer;
        srcNode.enableRemoting(&pingPongServer);
    
        return app.exec();
    }
    

    MyService.java

    package com.kdab.training;
    
    import android.content.Context;
    import android.content.Intent;
    import android.util.Log;
    import org.qtproject.qt5.android.bindings.QtService;
    
    public class MyService extends QtService
    {
        public static void startMyService(Context ctx) {
            ctx.startService(new Intent(ctx, MyService.class));
        }
    
        @Override
        public void onDestroy() {
            super.onDestroy();
            Log.d("Service Test", "Called onDestroy");
        }
    
        public void quit() {
            stopSelf();
        }
    }
    

    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.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved