问题描述
所以我实际上没有问题,因为我已经解决了它,但是如果其他人遇到这个问题,有一个简洁的解决方案总是很好的.
So i don't actually have a question because i've already solved it, but in case someone else runs into this issue it's always nice to have a neat solution.
虽然有很多无法在没有调用 Looper.prepare() 的线程内创建处理程序"
- 问题没有用 xamarin 标记.(所以他们的都是 java,我有 0 个匹配项无法在没有调用 Looper.prepare() [xamarin] 的线程内创建处理程序")
And while there is a plentitude of "Can't create handler inside thread which has not called Looper.prepare()"
- questions there is none tagged with xamarin. (so theirs is all java and i had 0 matches for "Can't create handler inside thread which has not called Looper.prepare() [xamarin]")
推荐答案
该问题的产生是因为您试图从其他线程处理 UI.如果要更改 UI,必须从 UI 线程调用 UI 更改.
The issue is generated because You tried to do work on UI from other thread. If you want to change UI, Must call UI changes from UI thread.
Xamarin 安卓:
Xamarin Android:
activity.RunOnUiThread(() =>
{
// Write your code here
});
Xamarin IOS:
Xamarin IOS:
nsObject.BeginInvokeOnMainThread(() =>
{
// Write your code here
});
Xamarin 表单:
Xamarin Forms:
Device.BeginInvokeOnMainThread(() =>
{
// Write your code here
});
这篇关于无法在尚未调用 Looper.prepare() [xamarin] 的线程内创建处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!