Starting multiple android services
-
Hello,
I want to start multiple Android services. In this case, I am trying to start two services. Regardless of the service's type, the first one always works just fine. However, the second one does not start, no matter what.
Here's what I have:
main.cpp
QCoreApplication app(argc, argv, true); BootService::getInstance()->start_service(); WebService::getInstance()->start_service(); return app.exec();
BootService.cpp
... void BootService::start_service() { QJniObject::callStaticMethod<void>("tech.secureme.services.BootService", "startService", "(Landroid/content/Context;)V", QNativeInterface::QAndroidApplication::context()); } ...
WebService.cpp
... void WebService::start_service() { QJniObject::callStaticMethod<void>("tech.secureme.services.WebService", "serviceStart", "(Landroid/content/Context;)V", QNativeInterface::QAndroidApplication::context()); } ...
BootService.java
public class BootService extends QtService { @Override public int onStartCommand(Intent intent, int flags, int startId) { return Service.START_STICKY; } public static void startService(Context ctx) { ctx.startService(new Intent(ctx, BootService.class)); } }
WebService.java
public class WebService extends QtService { @Override public int onStartCommand(Intent intent, int flags, int startId) { return Service.START_STICKY; } public static void serviceStart(Context ctx) { ctx.startService(new Intent(ctx, WebService.class)); } }
AndroidManifest.xml
.... <service android:process=":qt_service" android:name=".services.BootService"> <meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --" /> <meta-data android:name="android.app.arguments" android:value="--service" /> <meta-data android:name="android.app.background_running" android:value="true" /> </service> <service android:process=":qt_service" android:name=".services.WebService"> <meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --" /> <meta-data android:name="android.app.arguments" android:value="--web_service" /> <meta-data android:name="android.app.background_running" android:value="true" /> </service> ...
Why does the first service always start, but the second one doesn't ? How can I fix that?
-
-
Hello,
I want to start multiple Android services. In this case, I am trying to start two services. Regardless of the service's type, the first one always works just fine. However, the second one does not start, no matter what.
Here's what I have:
main.cpp
QCoreApplication app(argc, argv, true); BootService::getInstance()->start_service(); WebService::getInstance()->start_service(); return app.exec();
BootService.cpp
... void BootService::start_service() { QJniObject::callStaticMethod<void>("tech.secureme.services.BootService", "startService", "(Landroid/content/Context;)V", QNativeInterface::QAndroidApplication::context()); } ...
WebService.cpp
... void WebService::start_service() { QJniObject::callStaticMethod<void>("tech.secureme.services.WebService", "serviceStart", "(Landroid/content/Context;)V", QNativeInterface::QAndroidApplication::context()); } ...
BootService.java
public class BootService extends QtService { @Override public int onStartCommand(Intent intent, int flags, int startId) { return Service.START_STICKY; } public static void startService(Context ctx) { ctx.startService(new Intent(ctx, BootService.class)); } }
WebService.java
public class WebService extends QtService { @Override public int onStartCommand(Intent intent, int flags, int startId) { return Service.START_STICKY; } public static void serviceStart(Context ctx) { ctx.startService(new Intent(ctx, WebService.class)); } }
AndroidManifest.xml
.... <service android:process=":qt_service" android:name=".services.BootService"> <meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --" /> <meta-data android:name="android.app.arguments" android:value="--service" /> <meta-data android:name="android.app.background_running" android:value="true" /> </service> <service android:process=":qt_service" android:name=".services.WebService"> <meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --" /> <meta-data android:name="android.app.arguments" android:value="--web_service" /> <meta-data android:name="android.app.background_running" android:value="true" /> </service> ...
Why does the first service always start, but the second one doesn't ? How can I fix that?