CodePlague
CodePlague

Reputation: 97

How to Call this Method from OnCreate - Android C# Xamarin

I am wondering how I am meant to Call public static async Task CopyAssetAsync(Activity activity) from the OnCreate method.

  public static async Task CopyAssetAsync(Activity activity)
    {
        {
            var notesPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "NotesData.txt");

            if (!File.Exists(notesPath))
            {
                try
                {

UPDATE 1:

protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            ActionBar.Hide();

            btnAdd = FindViewById<Button>(Resource.Id.btnAdd);
            //Notes
            notesList = FindViewById<ListView>(Resource.Id.lvNotes);


            //Where I am trying to call the method...
            CopyAssetAsync();

UPDATE 2:

enter image description here

Upvotes: 0

Views: 1837

Answers (1)

Himanshu Dwivedi
Himanshu Dwivedi

Reputation: 8139

You have to use await keyword while calling and make the OnCreate() method async :

protected override async void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);

    // Set our view from the "main" layout resource
    SetContentView(Resource.Layout.Main);
    ActionBar.Hide();

    btnAdd = FindViewById<Button>(Resource.Id.btnAdd);
    //Notes
    notesList = FindViewById<ListView>(Resource.Id.lvNotes);


    //Where I am trying to call the method...
     await CopyAssetAsync(this);
}

Upvotes: 2

Related Questions