I'm trying to create a child class of "Android.App.Application" to override "OnCreate()", but I can't get it working. Here's my code:
namespace MonoAndroidAcra {
[Application(Debuggable=true,
Label="insert label here",
ManageSpaceActivity = typeof(MainActivity))]
class AcraApp : Application {
public override void OnCreate() {
base.OnCreate();
}
}
}
MainActivity
is just the default example activity.
Now, when I debug the project I get a System.NotSupportedException
:
Unable to activate instance of type MonoAndroidAcra.AcraApp from native handle 405191a0
No call stack is available for this exception.
How do I do this correctly? I couldn't find any examples for this.
I'm using the latest stable version of Mono for Android.
You need to add this constructor to your class in order to make it work:
public AcraApp (IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
{
}
This was a "leaky abstraction", explained by a Xamarin Team member, that have been fixed in the latest Xamarin Android Version 4.12.2, in which it is not required anymore to add this missing constructor. The Android SDK 22.6 is also required to properly function with this Xamarin version. However updating the SDK only will not fix this problem, this is really Xamarin related.
For anyone using older version, Greg's solution should still be used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With