尝试运行应用程序并在我的MainActivity类OnCreate方法中,我有以下内容:
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
bcastRx = new BroadcastRx();
bcastRx.Received += HandleOnBroadcastReceive;
RegisterReceiver (bcastRx, new IntentFilter("hello"));
...
Receiver类看起来像这样:
[BroadcastReceiver]
[Register("android/content/BroadcastReceiver", DoNotGenerateAcw=true)]
class BroadcastRx : BroadcastReceiver{
public delegate void Receive(Context c, Intent intent);
public event Receive Received;
public override void OnReceive(Context c, Intent intent) {
if(Received != null)
Received(c,intent);
}
}
在调用RegisterReceiver的行上,我在Nexus 5上获得了一个SIGSEGV(但不是在模拟器上)。回溯:
[mono-rt] at <unknown> <0xffffffff>
[mono-rt] at (wrapper managed-to-native) object.wrapper_native_0xb4db2c65 (intptr,intptr,intptr,intptr,Android.Runtime.JValue[]) <IL 0x0012b, 0xffffffff>
[mono-rt] at (wrapper delegate-invoke) <Module>.invoke_intptr_intptr_intptr_intptr_intptr_JValue[] (intptr,intptr,intptr,intptr,Android.Runtime.JValue[]) <IL 0x00069, 0xffffffff>
[mono-rt] at Android.Runtime.JNIEnv.CallNonvirtualObjectMethod (intptr,intptr,intptr,Android.Runtime.JValue[]) [0x00060] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:542
[mono-rt] at Android.Content.ContextWrapper.RegisterReceiver (Android.Content.BroadcastReceiver,Android.Content.IntentFilter) [0x00089] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Content.ContextWrapper.cs:2169
[mono-rt] at client.Android.MainActivity.OnCreate (Android.OS.Bundle) [0x00038] in c:\Work\xamarin\client\Android\MainActivity.cs:31
[mono-rt] at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.App.Activity.cs:2380
[mono-rt] at (wrapper dynamic-method) object.47ba580a-bf7b-4507-8c4d-53e613b2dc06 (intptr,intptr,intptr) <IL 0x00017, 0x00043>
[mono-rt] at (wrapper native-to-managed) object.47ba580a-bf7b-4507-8c4d-53e613b2dc06 (intptr,intptr,intptr) <IL 0x00023, 0xffffffff>
[mono-rt]
[mono-rt] =================================================================
[mono-rt] Got a SIGSEGV while executing native code. This usually indicates
[mono-rt] a fatal error in the mono runtime or one of the native libraries
[mono-rt] used by your application.
[mono-rt] =================================================================
[mono-rt]
[libc] Fatal signal 11 (SIGSEGV), code 1, fault addr 0x3e in tid 29973 (m.test.client)
关于我可能做错什么的任何想法?
编辑我试过了:
答案 0 :(得分:0)
好吧我终于找到了;试错,所以我无法解释为什么这是正确的答案。
[BroadcastReceiver]
// remove this -> [Register("android/content/BroadcastReceiver", DoNotGenerateAcw=true)]
class BroadcastRx : BroadcastReceiver{
public delegate void Receive(Context c, Intent intent);
public event Receive Received;
public override void OnReceive(Context c, Intent intent) {
if(Received != null)
Received(c,intent);
}
}
魔术。