diff options
author | E.Z. Hart <hartez@gmail.com> | 2016-09-27 12:11:38 -0600 |
---|---|---|
committer | E.Z. Hart <hartez@gmail.com> | 2016-09-27 12:11:38 -0600 |
commit | 87a79d14aa28bf77b70ad889a37964202ed4a302 (patch) | |
tree | e18da839993718333ebc6a7cb0e5f9c150018713 | |
parent | d9a550b408169580ae2bd0e5634d9fe2f46a8ccc (diff) | |
download | xamarin-forms-87a79d14aa28bf77b70ad889a37964202ed4a302.tar.gz xamarin-forms-87a79d14aa28bf77b70ad889a37964202ed4a302.tar.bz2 xamarin-forms-87a79d14aa28bf77b70ad889a37964202ed4a302.zip |
Reuse Handler when invoking on main thread
-rw-r--r-- | Xamarin.Forms.Platform.Android/Forms.cs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Xamarin.Forms.Platform.Android/Forms.cs b/Xamarin.Forms.Platform.Android/Forms.cs index a2a063c9..6f3346fb 100644 --- a/Xamarin.Forms.Platform.Android/Forms.cs +++ b/Xamarin.Forms.Platform.Android/Forms.cs @@ -262,11 +262,16 @@ namespace Xamarin.Forms double _microSize; double _smallSize; + static Handler s_handler; + public void BeginInvokeOnMainThread(Action action) { - var activity = Context as Activity; - if (activity != null) - activity.RunOnUiThread(action); + if (s_handler == null || s_handler.Looper != Looper.MainLooper) + { + s_handler = new Handler(Looper.MainLooper); + } + + s_handler.Post(action); } public Ticker CreateTicker() |