aspyct aspyct - 5 months ago 20
Android Question

Xamarin.Android Application not called anymore since XS 6

In our team, we recently updated to Xamarin Studio 6, as it's just out. Unfortunately, Something just broke in our Android application.

Roughly, we have an

Application
class with initialisation in OnCreate().

namespace MyNamespace
{
[Application(Theme="@style/MyTheme")]
public class MyApplication : Android.App.Application
{
public MyApplication (IntPtr handle, JniHandleOwnership transfer)
: base (handle, transfer)
{
}

public override void OnCreate ()
{
// Never called
}
}
}


But that
OnCreate()
isn't called anymore since we updated. A fellow dev reported that he reinstalled XS5, and still has the issue. This worked before, so something changed, but what?

Answer

As others have pointed out, new projects call Application.OnCreate() as expected.

I ended up creating a new project and drag/dropping all the files from one to another. Not nice, but at least it worked.

EDIT:

So here's what happened really.

Our application class inherited from another class, in a framework project, as follows:

class ParentApp
{
    void OnCreate()
    {
        SubclassInit();
    }

    abstract void SubclassInit();
}

[Application]
class MyApp : ParentApp
{
    void SubclassInit()
    {
    }
}

With this setup, nobody was called.

All we had to do is add an OnCreate() method in the MyApp class.

void OnCreate()
{
    base.OnCreate();
}

And now it's solved.

Comments