android 的UI更新 非主线程内引发的异常。
Android.Util.AndroidRuntimeException: Exception of type 'Android.Util.AndroidRuntimeException' was thrown.
解决办法:
public class ThreadDemo : Activity { TextView textview; protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); // Create a new TextView and set it as our view textview = new TextView (this); textview.Text = "Working.."; SetContentView (textview); ThreadPool.QueueUserWorkItem (o => SlowMethod ()); } private void SlowMethod () { Thread.Sleep (5000); RunOnUiThread (() => textview.Text = "Method Complete"); } }
参考:http://docs.xamarin.com/guides/android/advanced_topics/writing_responsive_applications