Rupert

::Me(C#,VC,MonoTouch,MonoforAndroid);

导航

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

努力加载评论中...
点击右上角即可分享
微信分享提示