dimanche 24 mai 2015

Android : Intent or Handler + listener + runnable?

My app is parsing data from an inputStream in a background thread. It must push messages to the gui depending on the read data.

Few months ago I did an implentation that runs something like this :

  • The activiy implements a specific listener interface (one method per message type, the message parameters are passed as a structured parameter of the method).
  • The activity registers the listener somewhere.
  • each time the reading thread has something to push to the activity, it creates a runnable that is pushed to a handler (created in gui thread). The runnable is executed in the activity thread and calls the listener's method.

That's works pretty smoothly but...

Some days ago while reading a book, I discovered intents. Itents may replace this structure by a simple intent broadcast with activity registering on needed intents.

Today, I wonder which solution would fit the best in terms of performance. Of course the first solution is more complex in terms of number of classes but that does not presume of the performance...

Anybody has any clue ?

Thanks

Julien

Aucun commentaire:

Enregistrer un commentaire