簡體   English   中英

Xamarin android c#調用或在3秒后顯示活動

[英]Xamarin android c# call or display an activity after 3 second

我想在3秒后打電話給我。 我試過使用線程,但是不起作用……

[Activity(Label = "App1", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{


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

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Login);
        Button myButton = FindViewById<Button>(Resource.Id.button4);

        myButton.Click += delegate
        {

            StartActivity(typeof(Register));
        };


        new Handler().postDelayed(new Runnable()
    {
        public void run()
    {
        //After 3 second will call this activity
        StartActivity(typeof(MainActivity));
    }
    }, 5000);


    }    

}
    myButton.Click += async delegate
    {
        await Task.Delay(3000);
        StartActivity(typeof(Register));
    };

lambda的語法

myButton.Click += async (sender, args) =>
{
     await Task.Delay(3000);
     StartActivity(typeof (Register));
};

您也可以使用

 Java.Lang.Runnable runnable = new Java.Lang.Runnable(() =>
        {
            Intent i = new Intent(this, typeof(MainActivity));
            StartActivity(i);
        });

        new Handler().PostDelayed(runnable, 1000);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM