Pergunta

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

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top