2017-06-01 58 views
0

在仿真器 - 棉花糖上運行代碼時出現以下錯誤。 請讓我知道可能是什麼原因。Xamarin.Android - 錯誤 - 實現AlarmManager.IOnAlarmListener

當我實現其他接口如IServiceConnection時,代碼不會拋出錯誤。

namespace ExampleNameSpace 
{ 
    public class TestAlarmListener : Java.Lang.Object, 
    AlarmManager.IOnAlarmListener 
    { 
     public TestAlarmListener(){} 
     public void OnAlarm(){ } 
    } 

    [Activity(Label = "AlarmActivity")] 
    public class AlarmActivity : Activity 
    { 
     protected override void OnCreate(Bundle savedInstanceState) 
     { 
      base.OnCreate(savedInstanceState); 
      SetContentView(Resource.Layout.Alarm); 
      TestAlarmListener listener = new TestAlarmListener(); 

     } 


    Error - 

    06-01 18:05:25.557: E/AppMessage(8848): Didn't find class 
    "md5d67d3b9255c5c503bc35ab778230d3db.TestAlarmListener" on path: 
    DexPathList[[zip file "/data/app/ExampleApp.ExamplePack- 
    1/base.apk"],nativeLibraryDirectories=[/data/app/ExampleApp.ExamplePack- 
    1/lib/arm, /data/app/ExampleApp.ExamplePack-1/base.apk!/lib/armeabi-v7a, 
    /vendor/lib, /system/lib]] 
+0

我得到了同樣的錯誤,你有沒有找到解決辦法的答案嗎? –

+0

我找到了答案,你必須實現2個更多的構造函數,並使用API​​> 19進行編譯,這裏是我的鬧鐘監聽器 –

回答

0

我發現你必須實現2個構造函數和與API> 19編譯這裏是我報警監聽

public class Test :Java.Lang.Object, AlarmManager.IOnAlarmListener 
{ 

    public Test() 
    { 

    } 
    public Test(IntPtr handle) 
    { 
     Handle = handle; 
    } 
    public Test(IntPtr handle, JniHandleOwnership transfer) 
    { 
    } 
    public IntPtr Handle { get; private set; } 

    public void Dispose() 
    { 

    } 

    public void OnAlarm() 
    { 
     Log.Info("AlarmToastReceiver", DateTime.Now.ToString()); 
    } 
}