Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't create handler inside thread which has not called Looper.prepare() [xamarin]

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.

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]")

like image 616
Dbl Avatar asked Nov 02 '15 18:11

Dbl


1 Answers

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 Android:

activity.RunOnUiThread(() =>
{
      // Write your code here         
});

Xamarin IOS:

nsObject.BeginInvokeOnMainThread(() =>
{
     // Write your code here                
});

Xamarin Forms:

Device.BeginInvokeOnMainThread(() =>
{
     // Write your code here
});
like image 58
Maulik Parmar Avatar answered Sep 30 '22 23:09

Maulik Parmar