Nothing happens on UI on Android app if i use threads in Xamarin

Whenever i try to execute another task in my Android app on Xamarin the user interface does never change if I do any calls on that. I don't know why, but it seems that i am missing something. I am working in Visual Studio with Xamarin. So i think c# or java solutions would be possible!?
1 answer

Using RunOnUiThread to see user interface changes in Xamarin

If you are in your own thread and the code looks similar to this:

//1. Code before your UI action

//2. Code that changes UI

//3. Code after your UI action

Than you need to do the following.

First you need to get the current instance of you main activity that you are in, this can be achieved like this:
In your MainActivity.cs you need to change the App loading to
// LoadApplication(new App(this));

In your "App" class you than write:
// public App(Object o)
and
// currentMainActivity = (Android.App.Activity)o;

After that you have everywhere in your code access to the current java main activity.
To do some UI actions in your threads, just use the following code:

//1. Code before your UI action

App.currentMainActivity.RunOnUiThread(() =>
{
// 2. Code that changes UI
});

//3. Code after your UI action

Taggings: