The eternal newbie
The eternal newbie

Reputation: 131

android intent vs observer

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

Answers (2)

minhaz
minhaz

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

  • Communicating with third party application and processes.
  • Receive system notification to perform a task
  • Application module reuse by third party app. (Ex taking pic)
  • Intent stays around and your app can retrieve data in some later time (Sticky Intent)

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

Alexander
Alexander

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

Related Questions