As a quick note today, if you’re working on a Scala project and get a compiler error message like this:
As a quick example of how to use a
Thread with a basic
Handler in an Android application, the following code creates a view where the text in the
TextView is updated to show the current date and time when the
Button is tapped.
Java source code
First, here’s the Java source code for a file class named
To show an Android Snackbar message from an Activity or Fragment, use Java code like this:
Snackbar.make(view, "going to: " + url, Snackbar.LENGTH_LONG).show();
One key is to remember to call the
show() method after
make(). I have a tendency to forget to call
show() and then wonder why my Snackbar message isn’t showing up. So maybe a better way to show that code is like this:
This page is a little unusual for me; it’s basically a terse summary of what I know about Android. I created it because I tend to (a) work with Android for a few weeks or months, and then (b) get away from it for several months, so this page helps me reload everything into my brain.
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 13.10, “How to send a message to an Akka Actor and wait for a reply.”
You have one actor that needs to ask another actor for some information, and needs an immediate reply. (The first actor can’t continue without the information from the second actor.)
ask methods to send a message to an Akka actor and wait for a reply, as demonstrated in the following example:
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 13.3, “How to communicate (send messages) between Scala/Akka actors.”
You’re building an actor-based application and want to send messages between actors.
Actors should be sent immutable messages with the
A few days ago I shared the source code for a simple Akka remote actor example. In that example I showed how to communicate between actors in two different JVMs using Scala and Akka. In that example I showed how to communicate between the two JVMs using
String messages because I didn’t want to make the example any harder than necessary.
Today, I’m taking that example just one step further to show how to communicate between actors on different JVMs by using custom objects for your messages.
$ sbt compile [warn] there were 6 deprecation warnings; re-run with -deprecation for details [warn] there were 4 feature warnings; re-run with -feature for details
How do I ’re-run with -deprecation’ or ’re-run with -feature’?
Akka actors FAQ: Can you share an "Akka Actors 101" example (a simple "Introduction to Akka Actors" example)?
Sure. If you're looking for a really simple tutorial, check out my Akka Actors "Hello, world" tutorial. If that one is overly simplified and you want something more, continue on here.