Radix
Radix

Reputation: 143

Subtle differences between an intent and an event?

What are the subtle differences between an intent and an event in Android app development? It is my understanding that both cause something to happen in response to user or system actions and that intents are global whereas events are more localized, but what are the more subtle differences.

Upvotes: 2

Views: 1310

Answers (2)

x-code
x-code

Reputation: 3000

Intents are the foundation of Android's very flexible inter process communication features. A new android programmer will want to learn all of their ins and outs right away because they enable types of code reuse that will save a great deal of time and effort.

The concept of an event is important in android as it would be in any modern event-driven operating system but it does not refer to a specific class or component. There are InputEvents which represent things like key clicks and touch events.

There are also SensorEvents that represent data from a hardware sensor (light sensor, proximity sensor, accelerometer and some others).

These events have some similarities but there is not a unified event framework or base class as there is with intents. The event an android developer will handle most often is a click event, and that is not even represented by a class because all you need to know is that it occurred and which view was clicked.

Upvotes: 0

Roy Hinkley
Roy Hinkley

Reputation: 10651

Intents are the messaging system used by the Android OS (similar to messages in Windows). Intents can vary in scope and even be used to communicate between apps. If I understand you correctly, events are raised by the OS. Events require a listener to 'handle' them. For instance, setting the onClick listener for a TextView will give you the ability to handle any taps on that TextView. Intents and events are mutually exclusive and should never be confused as interchangeable. You also need to set up a listener to handle intents that are sent out in the listeners onReceive event. But as stated in the comments, event is a generic concept and an intent is a concrete thing.

Upvotes: 1

Related Questions