如何发送…hreadStar

问题描述 投票:0回答:1

我有一个带有Viem模型的tapPage,我正在从VM敬酒,但出现异常

TabMenuMyArticlesava.Lang.RuntimeException: Can't toast on a thread that has not called Looper.prepare()

我不想DisplayAlert,我还能如何从MVVM向用户显示警报?我找到了这个 但是我不确定如何将它不只连接到Xamarin.Android

 new System.Threading.Thread(new ThreadStart(() =>
                    {

                        RunOnUiThread(() => { Toast.MakeText(ApplicationContext, "xxxxxx", ToastLength.Short).Show(); });
                    })).Start();
xamarin.forms
1个回答
1
投票

使用MainThread

MainThread.BeginInvokeOnMainThread(() =>
{
    Toast.MakeText(ApplicationContext, "xxxxxx", ToastLength.Short).Show();
});
© www.soinside.com 2019 - 2024. All rights reserved.