Forum Xamarin.Android

cannot convert from 'MyNamespace.MyAppClass.MainActivity' to 'System.Func<Android.App.Activity>'

In my App I am using the nuget package Acr.Support. Everything worked fine until I had no MyAppClass. Since I surrounded the MainActivity with an Application Class I can´t use the command :

UserDialogs.Init(this);

Error message:
cannot convert from 'MyNamespace.MyAppClass.MainActivity' to 'System.Func<Android.App.Activity>'

Here is my code:

` namespace MyNamespace
{
[Application]
public class MyAppClass : Android.App.Application
{
public AmadeusAppClass(IntPtr handle, global::Android.Runtime.JniHandleOwnership transfer) : base(handle, transfer)
{
}

    public override void OnCreate()
    {           
        //some stuff
    }

    [Activity(Label = "My App", MainLauncher = true, Theme = "@android:style/Theme.Holo.NoActionBar.Fullscreen")]
    public class MainActivity : Activity
    {            
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            UserDialogs.Init(this); 
            //"this" gives me error message saying that I can´t convert from from 'MyNamespace.MyAppClass.MainActivity' to 'System.Func<Android.App.Activity>'           
        }   
    }
}

}`

Any idea what I am doing wrong?

Tagged:

Answers

  • BerayBentesenBerayBentesen TRUniversity ✭✭✭✭
    edited November 2016

    What is this ?

        public override void OnCreate()
                {           
                       //some stuff
            }
    

    outside the Activity ?

  • GM.3293GM.3293 USMember

    I use the OnCreate method out of the application class level to have my instances of objects available in the entire App and for the entire Application lifecycle. But your question does not lead me to any idea I am doing wrong.

  • AllanRitchieAllanRitchie CAInsider, University ✭✭✭

    That is an odd error. Application.OnCreate is the best place to Init on android unless you are using mvvmcross or forms, in which case, there are better options.

    Please post a reproducible case on github and I can take a look: https://github.com/aritchie/userdialogs

  • GM.3293GM.3293 USMember

    Thanks Allan for your kindly support. I fixed the problem by myself. The problem was the version of the nuget package. It was not working with the version of 2.x. So I downgraded the version to 1.x.

Sign In or Register to comment.