Skip to content

A sample application on how to use the Android HaMeR (Handler, Message & Runnable)

Notifications You must be signed in to change notification settings

tinmegali/hamer

Repository files navigation

HaMeR - Handler, Message & Runnable

A sample application on how to use the Android HaMeR framework

The code is fully commented and illutrates how to post/send Runnable and Message objects between Threads and how to prepare a Thread using HandlerThread.

If you want to learn more, check this tutorial about the HaMeR framework.

The app is composed by:

  • Two Activities, one for Runnable e other for Message calls
  • Two HandlerThread objects
    • WorkerThread to receive and process calls from the UI
    • CounterThread to receive Message calls from the WorkerThread
  • And some utility classes and layout resources
  • The app has a simple UI with buttons to download some images and start a counter

Posting and receiving Runnables with RunnableActivity

  1. The RunnableActivity instantiate a background Thread called WorkerThread passing a Handler and a WorkerThread.Callback as parameters
  2. The activity makes a call on WorkerThread asking it to download a image.
  3. The download is done asynchronously on the background thread
  4. The WorkerThread sends the image to the RunnableActivity posting a Runnable to it using a Handler that it received as parameter earlier.

Sending and Receiving Messages with MessageActivity

  1. The MessageActivity instantiate a background Thread calledWorkerThread passing a Handler as parameters
  2. The activity makes a call on WorkerThread asking it to download a specific image or download a random one.
  3. The download is done asynchronously on the background thread
  4. The WorkerThread create a Message using the 'key' defined on the MessageActivity and passing the image downloaded as a parameter object.
  5. The Message in sent to the MessageActivity using a Handler that WorkerThread received as parameter earlier.
  6. The Handler on MessageActivity processes the Message, get the object from it and exhibits on the UI

About

A sample application on how to use the Android HaMeR (Handler, Message & Runnable)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages