message

Android: How to send a message from a Thread to a Handler

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 ThreadHandlerActivity:

How to show an Android Snackbar message

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:

An Android cheat sheet (my notes, main concepts)

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.

The Case for Message-Driven (Understanding Async, Non-Blocking, Concurrent, Parallel and More) alvin August 18, 2015 - 4:16pm

How to send a message to an Akka Actor and wait for a reply

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.”

Problem

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.)

Solution

Use the ? or ask methods to send a message to an Akka actor and wait for a reply, as demonstrated in the following example:

How to send and receive messages between Scala/Akka actors

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.”

Problem

You’re building an actor-based application and want to send messages between actors.

Solution

Actors should be sent immutable messages with the ! method.

A second Akka remote example: Sending objects as messages

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.

Scala SBT: How to “re-run with -deprecation” (or -feature)

Scala FAQ: When compiling a Scala application with SBT, I get warning messages like these:

$ 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’?