我想在启动时运行我的后台服务,我在Android上使用Xamarin Forms。我按照Rob Gibbens https://github.com/RobGibbens/XamarinFormsBackgrounding的一个很好的例子“LongRunningTaskService”创建了这个服务 并且工作得很好,但我在启动时需要它,而不是由UI触发。我在启动时添加了服务,并且在mscorlib.dll启动后立即发生了崩溃。即使删除了所有代码并且除了广播监听器之外没有做任何事情,也会发生崩溃。
这里是广播听众
using Android.App;
using Android.Content;
namespace FormsBackgrounding.Droid
{
[BroadcastReceiver(Enabled = true)]
[IntentFilter(new[] { Android.Content.Intent.ActionBootCompleted })]
public class StartReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
//if (intent.Action == Intent.ActionBootCompleted)
//{
//Intent timerIntent = new Intent(context, typeof(LongRunningTaskService));
//Application.Context.StartService(timerIntent);
//}
}
}
}
这里是清单
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.arteksoftware.formsbackgrounding">
<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:label="FormsBackgrounding">
<receiver android:name="StartReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name=".LongRunningTaskService" ></service>
</application>
</manifest>
日志崩溃
Assembly Loader probing location: '/storage/emulated/0/Android/data/com.arteksoftware.formsbackgrounding/files/.__override__/mscorlib.dll'.
637): The first listener is added
Image addref mscorlib[0xe1bfe280] -> /storage/emulated/0/Android/data/com.arteksoftware.formsbackgrounding/files/.__override__/mscorlib.dll[0xeaf8c800]: 2
Prepared to set up assembly 'mscorlib' (/storage/emulated/0/Android/data/com.arteksoftware.formsbackgrounding/files/.__override__/mscorlib.dll)
AOT module '/storage/emulated/0/Android/data/com.arteksoftware.formsbackgrounding/files/.__override__/mscorlib.dll.so' not found: dlopen failed: library "/data/app/
/lib/x86/libaot-mscorlib.dll.so" not found
AOT module '/Users/builder/data/lanes/4009/df84ee74/source/monodroid/builds/install/mono-x86/lib/mono/aot-cache/x86/mscorlib.dll.so' not found: dlopen failed: library "/data/app/
/lib/x86/libaot-mscorlib.dll.so" not found
Assembly Loader loaded assembly from location: '/storage/emulated/0/Android/data/com.arteksoftware.formsbackgrounding/files/.__override__/mscorlib.dll'.
Config attempting to parse: '/storage/emulated/0/Android/data/com.arteksoftware.formsbackgrounding/files/.__override__/mscorlib.dll.config'.
Config attempting to parse: '/Users/builder/data/lanes/4009/df84ee74/source/monodroid/builds/install/mono-x86/etc/mono/assemblies/mscorlib/mscorlib.config'.
mono_threads_platform_set_priority: unknown policy 3
Fatal signal 6 (SIGABRT), code -6 in tid 1462 (msbackgrounding)
debuggerd: handling request: pid=1445 uid=10068 gid=10068 tid=1462
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'Android/vbox86p/vbox86p:7.0/NRD90M/genymo09131924:userdebug/test-keys'
Revision: '0'
ABI: 'x86'
pid: 1445, tid: 1462, name: msbackgrounding >>> com.arteksoftware.formsbackgrounding <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
Abort message: 'mono_threads_platform_set_priority: unknown policy 3'
eax 00000000 ebx 000005a5 ecx 000005b6 edx 00000006
esi cd3ef978 edi cd3ef920
xcs 00000023 xds 0000002b xes 0000002b xfs 0000006b xss 0000002b
eip ef775bb9 ebp cd3ef748 esp cd3ef6ec flags 00000292
backtrace:
#00 pc 00000bb9 [vdso:ef775000] (__kernel_vsyscall+9)
#01 pc 0007a2ec /system/lib/libc.so (tgkill+28)
#02 pc 00075b35 /system/lib/libc.so (pthread_kill+85)
#03 pc 0002784a /system/lib/libc.so (raise+42)
#04 pc 0001ee26 /system/lib/libc.so (abort+86)
#05 pc 00270657 /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so
任何人遇到同样的问题?有任何解决方法吗?