Event Driven Programming ¥ A type of programming where: ¥ Flow of control is determined by events. ¥ Events: ¥ Physical occurrences in the real world ¥ User actions (button click, menu selection) ¥ Messages (text message, phone call) ¥ Sensor inputs (GPS, orientation change) ¥ Program actions (Display, outgoing message) ¥ Event Handlers ¥ Software objects (blocks) that we can program to take action in response to events. Levels of Event Processing Operating System Level Ð Android Do forever: Listen for events and dispatch them to the right event handler. Hardware Level Ð Detect Events App Level Ð Hello Purr Compass App App Event Handlers User: Button Click in Hello Purr Orientation Sensor: Phone Moved Main Controller's Event Loop ¥ Repeat forever (while the phone is running) ¥ Listener: If an event is detected put it in the pending event list. ¥ Dispatcher: Take the highest priority event from the event list and send it to the appropriate event handler. Pending Event E1, E2, E3, E4, ... List To event From Hardware Listener handler Dispatcher Ek Ek Event Handler ¥ Wait (sleep) for an event to be delivered to you. ¥ When sent an event by the dispatcher, wake up and ¥ Do the prescribed list of actions. ¥ Go back to sleep. ¥ Text Message Received Handler ¥ When a text message is received from a given phone number ¥ Do something with the message. ¥ Go back to sleep. AI's Message Received Handler App Inventor's Button Click Handler