ViewModel updating by a non UI thread

57 views
Skip to first unread message

Lorenzo Maiorfi

unread,
May 8, 2013, 3:52:31 AM5/8/13
to android...@googlegroups.com
Hi.

Is there a smart way to run on UI thread code that updates UI whenever an observable value is updated by a non-UI thread?

At this time the only viable solution seems to be passing to ViewModel constructor a reference to an Activity or to an Handler.

Any ideas?

Andy Tsui

unread,
May 9, 2013, 12:59:09 AM5/9/13
to android...@googlegroups.com
More or less this is the best way. Moreover, I always pass Activity to
constructor of View Models as you really need it in many many
situations, for example, to start another activity.
> --
> You received this message because you are subscribed to the Google Groups
> "AndroidBinding" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to androidbindin...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

martin martinez

unread,
May 9, 2013, 8:58:52 AM5/9/13
to android...@googlegroups.com
The other way to do is using a BroadCast Receiver

Andy Tsui

unread,
May 9, 2013, 8:29:12 PM5/9/13
to android...@googlegroups.com
You might noticed that there's an experimental (under
gueei.binding.labs) EventAggregator, which is a light weight
implementation for routing events without dependency.

I personally would suggest using that one (over Broadcast receiver),
but still need to pass a Context to the VM.
Reply all
Reply to author
Forward
0 new messages