我有自动启动的服务 此服务每4秒仅显示一个小文本。
当我重新启动模拟器时,会发生以下情况:
12-02 16:09:36.336: W/ContextImpl(2455): Implicit intents with startService are not safe: Intent { act=com.companyname.TestApp.Localisation (has extras) } android.content.ContextWrapper.startService:613 android.content.ContextWrapper.startService:613 md52fbe3486fee5a5395f40f60a143816fe.BootReceiver.n_onReceive:-2
12-02 16:09:36.653: D/Mono(2455): DllImport searching in: '__Internal' ('(null)').
12-02 16:09:36.653: D/Mono(2455): Searching for 'java_interop_jnienv_call_int_method_a'.
12-02 16:09:36.653: D/Mono(2455): Probing 'java_interop_jnienv_call_int_method_a'.
12-02 16:09:36.653: D/Mono(2455): Found as 'java_interop_jnienv_call_int_method_a'.
12-02 16:09:36.978: D/Mono(2455): DllImport searching in: '__Internal' ('(null)').
12-02 16:09:36.979: D/Mono(2455): Searching for 'java_interop_jnienv_call_static_int_method_a'.
12-02 16:09:36.979: D/Mono(2455): Probing 'java_interop_jnienv_call_static_int_method_a'.
12-02 16:09:36.979: D/Mono(2455): Found as 'java_interop_jnienv_call_static_int_method_a'.
12-02 16:09:37.024: D/GPSService(2455): Démarré à 02/12/2017 15:09:37
服务开始更正,所以在这里15:09:37 然后进一步:
12-02 16:09:45.517: D/GPSService(2455): Depuis 00:00:08.4857240 (Démarré le 02/12/2017 15:09:37)
12-02 16:09:49.503: D/GPSService(2455): Depuis 00:00:12.4889240 (Démarré le 02/12/2017 15:09:37)
12-02 16:09:53.577: D/GPSService(2455): Depuis 00:00:16.5627150 (Démarré le 02/12/2017 15:09:37)
12-02 16:09:55.761: D/AndroidRuntime(2455): Shutting down VM
12-02 16:09:56.039: E/AndroidRuntime(2455): FATAL EXCEPTION: main
12-02 16:09:56.039: E/AndroidRuntime(2455): Process: com.companyname.TestApp, PID: 2455
12-02 16:09:56.039: E/AndroidRuntime(2455): java.lang.RuntimeException: Unable to instantiate receiver com.companyname.TestApp.BootReceiver: java.lang.ClassNotFoundException: Didn't find class "com.companyname.TestApp.BootReceiver" on path: DexPathList[[zip file "/data/app/com.companyname.TestApp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.TestApp-1/lib/x86, /system/fake-libs, /data/app/com.companyname.TestApp-1/base.apk!/lib/x86, /system/lib, /vendor/lib]]
12-02 16:09:56.039: E/AndroidRuntime(2455): at android.app.ActivityThread.handleReceiver(ActivityThread.java:3021)
12-02 16:09:56.039: E/AndroidRuntime(2455): at android.app.ActivityThread.-wrap18(ActivityThread.java)
12-02 16:09:56.039: E/AndroidRuntime(2455): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1561)
12-02 16:09:56.039: E/AndroidRuntime(2455): at android.os.Handler.dispatchMessage(Handler.java:102)
12-02 16:09:56.039: E/AndroidRuntime(2455): at android.os.Looper.loop(Looper.java:154)
12-02 16:09:56.039: E/AndroidRuntime(2455): at android.app.ActivityThread.main(ActivityThread.java:6119)
12-02 16:09:56.039: E/AndroidRuntime(2455): at java.lang.reflect.Method.invoke(Native Method)
12-02 16:09:56.039: E/AndroidRuntime(2455): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
12-02 16:09:56.039: E/AndroidRuntime(2455): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
12-02 16:09:56.039: E/AndroidRuntime(2455): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.companyname.TestApp.BootReceiver" on path: DexPathList[[zip file "/data/app/com.companyname.TestApp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.TestApp-1/lib/x86, /system/fake-libs, /data/app/com.companyname.TestApp-1/base.apk!/lib/x86, /system/lib, /vendor/lib]]
12-02 16:09:56.039: E/AndroidRuntime(2455): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
12-02 16:09:56.039: E/AndroidRuntime(2455): at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
12-02 16:09:56.039: E/AndroidRuntime(2455): at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
12-02 16:09:56.039: E/AndroidRuntime(2455): at android.app.ActivityThread.handleReceiver(ActivityThread.java:3016)
12-02 16:09:56.039: E/AndroidRuntime(2455): ... 8 more
12-02 16:09:57.629: D/GPSService(2455): Depuis 00:00:20.6148070 (Démarré le 02/12/2017 15:09:37)
12-02 16:10:01.701: D/GPSService(2455): Depuis 00:00:24.6865620 (Démarré le 02/12/2017 15:09:37)
12-02 16:10:05.704: D/GPSService(2455): Depuis 00:00:28.6900010 (Démarré le 02/12/2017 15:09:37)
12-02 16:10:09.711: D/GPSService(2455): Depuis 00:00:32.6963410 (Démarré le 02/12/2017 15:09:37)
服务继续工作,每隔4秒发送一次“Depuis ......”。
BootReceiver.cs的预览
[BroadcastReceiver (Enabled = true)]
[IntentFilter (new[] { Intent.ActionBootCompleted }, Categories = new[] { Intent.CategoryDefault })]
public class BootReceiver : BroadcastReceiver
的AndroidManifest.xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:label="TestApp.Android">
<receiver android:name=".BootReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
GPSService.cs
[Service(Enabled = true,
IsolatedProcess = false,
Exported = false)]
[IntentFilter (new String[] { "com.companyname.TestApp.Localisation" })]
class GPSService : IntentService