Android: QtService doesn't call onDestroy after calling stopSelf
Unsolved
Mobile and Embedded
-
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.