Hi folks,

I'm trying to find a good approach to FRP and threading on Android. I know 
that I can use Scaloid and Macroid to run things on the main/UI thread. The 
problem is getting other operations off the UI thread.

First I tried using RxJava, via the rxjava-scala and rxjava-android 
adapters. I could get this to work:

    val values = Observable.interval(200 millis).take(100).map(_.toString)

    values.subscribe(value => {
      Log.d("Main Thread", (Looper.getMainLooper.getThread == 
Thread.currentThread()).toString ) // always false
      runOnUiThread( humidity_view.setText(value))
    })

Is this a good pattern? I wasn't sure, so I also tried the specifying 
threads according to: 
http://pommedeterresautee.blogspot.com/2013/11/rxjava-on-android-with-scala-awesome.html

class RxThread[T](o:Observable[T]) {
   def execAsync[T] = {
    o.subscribeOn(Schedulers.newThread)
      .observeOn(AndroidSchedulers.mainThread())
      .materialize
  }}


But the examples in that post doesn't work. There are lots of problems 
converting between Java Schedulers and Scala Schedulers. I think something 
in the RxJava packages changed.

I also looked into Scala.Rx after seeing Macroid using it, but it's unclear 
to me how to make it work on Android with appropriate threading and 
execution contexts.

I've read all the easily Googleable stuff on FRP for Scala on Android, but 
I've having trouble putting together an approach that works. Any help would 
be welcome. Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"scala-on-android" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to