在启动应用程序后,服务会自动重新启动(
Running services
菜单中0个进程和1个服务),如图所示(MyActivities)。
MyActivities (0 processes and 1 service)
我的manifest.xml(只包含相关行):<service android:process=":qt" android:name="org.qtproject.example.MyService">
<!-- android:process=":qt" is needed to force the service to run on a separate process than the Activity -->
<!-- Application arguments -->
<meta-data android:name="android.app.arguments" android:value="-service"/>
<!-- Application arguments -->
<!-- If you are using the same application (.so file) for activity and also for service, then you
need to use *android.app.arguments* to pass some arguments to your service in order to know which
one is which.
-->
<!-- Application to launch -->
<meta-data android:name="android.app.lib_name" android:value="MyService"/>
<!-- Application to launch -->
<!-- Ministro -->
<meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
<meta-data android:name="android.app.repository" android:value="default"/>
<meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
<meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
<!-- Ministro -->
<!-- Deploy Qt libs as part of package -->
<meta-data android:name="android.app.bundle_local_qt_libs" android:value="-- %%BUNDLE_LOCAL_QT_LIBS%% --"/>
<meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
<meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
<!-- Deploy Qt libs as part of package -->
<!-- Run with local libs -->
<meta-data android:name="android.app.use_local_qt_libs" android:value="-- %%USE_LOCAL_QT_LIBS%% --"/>
<meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
<meta-data android:name="android.app.load_local_libs" android:value="-- %%INSERT_LOCAL_LIBS%% --"/>
<meta-data android:name="android.app.load_local_jars" android:value="-- %%INSERT_LOCAL_JARS%% --"/>
<meta-data android:name="android.app.static_init_classes" android:value="-- %%INSERT_INIT_CLASSES%% --"/>
<!-- Run with local libs -->
<!-- Messages maps -->
<meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
<meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
<meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
<!-- Messages maps -->
<!-- Background running -->
<meta-data android:name="android.app.background_running" android:value="true"/>
<!-- Background running -->
</service>
我的服务(Java部分):
package org.qtproject.example;
import android.content.Context;
import android.content.Intent;
import org.qtproject.qt5.android.bindings.QtService;
public class MyService extends QtService {
public static void startMyService(Context context) {
Intent intent = new Intent(context, MyService.class); // New Intent;
context.startService(intent); // Start service;
}
}
服务重新启动时的日志记录:
E/ActivityManager( 1553): ANR in org.qtproject.example:qt
E/ActivityManager( 1553): PID: 3006
E/ActivityManager( 1553): Reason: Executing service org.qtproject.example/.MyService
E/ActivityManager( 1553): Load: 0.59 / 0.56 / 0.24
E/ActivityManager( 1553): CPU usage from 17710ms to 0ms ago:
E/ActivityManager( 1553): 2.3% 1553/system_server: 0.9% user + 1.3% kernel / faults: 2515 minor 1 major
E/ActivityManager( 1553): 1.5% 1146/surfaceflinger: 0% user + 1.4% kernel / faults: 2 minor
E/ActivityManager( 1553): 1.4% 1668/com.android.systemui: 0.5% user + 0.9% kernel / faults: 2944 minor
E/ActivityManager( 1553): 0.3% 1150/adbd: 0% user + 0.3% kernel / faults: 176 minor
E/ActivityManager( 1553): 0.2% 2194/com.google.android.gms: 0.2% user + 0% kernel / faults: 2607 minor
E/ActivityManager( 1553): 0.1% 2761/com.android.settings: 0.1% user + 0% kernel / faults: 1130 minor
E/ActivityManager( 1553): 0.1% 1141/logd: 0% user + 0% kernel / faults: 1 minor
E/ActivityManager( 1553): 0% 1155/mediaserver: 0% user + 0% kernel / faults: 4 minor
E/ActivityManager( 1553): 0% 1724/com.google.android.gms.persistent: 0% user + 0% kernel / faults: 8 minor
E/ActivityManager( 1553): 0% 1776/com.android.phone: 0% user + 0% kernel / faults: 2 minor
E/ActivityManager( 1553): 0% 1797/com.android.launcher: 0% user + 0% kernel / faults: 607 minor
E/ActivityManager( 1553): 0% 2030/com.google.process.gapps: 0% user + 0% kernel / faults: 344 minor
E/ActivityManager( 1553): +0% 3027/logcat: 0% user + 0% kernel
E/ActivityManager( 1553): 3.2% TOTAL: 1.1% user + 1.7% kernel + 0.1% iowait + 0.1% softirq
E/ActivityManager( 1553): CPU usage from 1336ms to 1838ms later:
E/ActivityManager( 1553): 16% 1553/system_server: 4% user + 12% kernel / faults: 15 minor
E/ActivityManager( 1553): 14% 1792/Binder_4: 2% user + 12% kernel
E/ActivityManager( 1553): 1.8% 1146/surfaceflinger: 0% user + 1.8% kernel
E/ActivityManager( 1553): 1.8% 1200/Binder_1: 0% user + 1.8% kernel
E/ActivityManager( 1553): 1.8% 2761/com.android.settings: 1.8% user + 0% kernel / faults: 8 minor
E/ActivityManager( 1553): 1.8% 2761/ndroid.settings: 0% user + 1.8% kernel
E/ActivityManager( 1553): 9.1% TOTAL: 1% user + 6.1% kernel + 2% iowait
I/ActivityManager( 1553): Killing 3006:org.qtproject.example:qt/u0a58 (adj 0): bg anr
W/libprocessgroup( 1553): failed to open /acct/uid_10058/pid_3006/cgroup.procs: No such file or directory
W/libprocessgroup( 1553): failed to open /acct/uid_10058/pid_3006/cgroup.procs: No such file or directory
W/ActivityManager( 1553): Scheduling restart of crashed service org.qtproject.example/.MyService in 43754ms
D/EGL_emulation( 1668): eglMakeCurrent: 0xb312e100: ver 2 0
W/ResourceType( 2761): No package identifier when getting value for resource number 0x00000000
W/PackageManager( 2761): Failure retrieving resources for org.qtproject.example: Resource ID #0x0
W/ResourceType( 2761): No package identifier when getting value for resource number 0x00000000
W/PackageManager( 2761): Failure retrieving resources for com.google.android.gsf.login: Resource ID #0x0
W/ResourceType( 2761): No package identifier when getting value for resource number 0x00000000
W/PackageManager( 2761): Failure retrieving resources for org.qtproject.example: Resource ID #0x0
W/ResourceType( 2761): No package identifier when getting value for resource number 0x00000000
W/PackageManager( 2761): Failure retrieving resources for com.google.android.gsf.login: Resource ID #0x0
W/ResourceType( 2761): No package identifier when getting value for resource number 0x00000000
W/PackageManager( 2761): Failure retrieving resources for org.qtproject.example: Resource ID #0x0
W/ResourceType( 2761): No package identifier when getting value for resource number 0x00000000
W/PackageManager( 2761): Failure retrieving resources for com.google.android.gsf.login: Resource ID #0x0
W/ResourceType( 2761): No package identifier when getting value for resource number 0x00000000
W/PackageManager( 2761): Failure retrieving resources for org.qtproject.example: Resource ID #0x0
W/ResourceType( 2761): No package identifier when getting value for resource number 0x00000000
W/PackageManager( 2761): Failure retrieving resources for com.google.android.gsf.login: Resource ID #0x0
W/ResourceType( 2761): No package identifier when getting value for resource number 0x00000000
W/PackageManager( 2761): Failure retrieving resources for org.qtproject.example: Resource ID #0x0
W/ResourceType( 2761): No package identifier when getting value for resource number 0x00000000
W/PackageManager( 2761): Failure retrieving resources for com.google.android.gsf.login: Resource ID #0x0
W/ResourceType( 2761): No package identifier when getting value for resource number 0x00000000
W/PackageManager( 2761): Failure retrieving resources for org.qtproject.example: Resource ID #0x0
W/ResourceType( 2761): No package identifier when getting value for resource number 0x00000000
W/PackageManager( 2761): Failure retrieving resources for com.google.android.gsf.login: Resource ID #0x0
在此之后,该服务将不再处于活动状态!
这张图片中的My App
是我在Android Studio中编写的一个服务,它运行得非常完美。但是,在Qt中的服务存在问题。