Reputation: 131
I am wondering when I should favour an intent based approach over a classic oberserver design pattern in my Android app.
Would it be wize to use intent's to publish events within one activity?
Upvotes: 2
Views: 1037
Reputation: 4233
Definition
Observer maintain a list of dependents to notify a change. On the other side Intent is an abstract description of operation. Which can be received by same or multiple application to perform a task.
Synchronous VS Asynchronous
Observer is synchronous as the changes effect right-way. Intent is asynchronous.
Binding
Observer bindings are compile time. On the other side intent bindings are at run time
Secure
For internal communication observer is much secure as Intent will broadcast message and anyone can receive the message.
Intent provide additional functionality over Observer on Android platform
Would it be wise to use intent's to publish events within one activity?
This will depend on your requirement. Look into your requirement to see which one needed.
Upvotes: 1
Reputation: 48272
I think not because a new intent will usually bring a new activity unless your activity has been declared as single top. Anyway intents do not resemble observers much. A Handler can be a better approximation.
Upvotes: 0