Xamarin android c# 在 3 秒后调用或显示 activity
Xamarin android c# call or display an activity after 3 second
我想在 3 秒后呼叫 activity。我试过使用线程但是它不起作用......
[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);
我想在 3 秒后呼叫 activity。我试过使用线程但是它不起作用......
[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);