I am trying to setup a workbench for testing parts of an Android app... (reading log file rather than handling sensors data directly)

In the Android app, I am using Handler to send back messages to the main activity to perform user notification

What's the best pattern in pure java app to mimic it, sending messages to the main class and handling them ? I guess I have to set up a message queue, and synchronize the send/receive methods on the queue, but in the main app, should I write a runnable thread to check for new messages ?

Is there any existing implementation

有帮助吗?

解决方案

If there is nothing else done in your main thread but the receiving and processing of messages from the queue, you can just blocking wait for new messages.

If you cannot blocking wait, transfer the wait logic to a runnable implementing inner class (e.g. QueueWorker), that is executed by a worker thread inside your main class.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top