How to run code after a delay in Xamarin Android

amitairos picture amitairos · Aug 28, 2016 · Viewed 9.9k times · Source

I'm trying to show some code after a delay in my Android app.
The Java code for doing this is something like this:

new Handler().postDelayed(new Runnable()
{
   @Override
   public void run()
   {
     // your code that you want to delay here
   }
}, 1000/* 1000ms = 1sec delay */);

How do I do this in Xamarin.Android with C#?

Answer

R4j picture R4j · Aug 28, 2016

You can try this:

Handler h = new Handler();
Action myAction = () => 
{
    // your code that you want to delay here
};

h.PostDelayed(myAction, 1000);

Take a look at document