August 2015
Beginner
768 pages
18h 18m
English
Chapter 4
In This Chapter
Creating broadcast receivers
Organizing data from broadcast receivers
Restricting a receiver’s access
Chapter 3 of this minibook introduces a broadcast receiver for the purpose of running code at boot time. Here’s a summary of that chapter’s broadcast receiver news:
onReceive method. A receiver has no onCreate, onDestroy, or onAnythingElse methods — only onReceive. After Android finishes executing the onReceive method’s code, the broadcast receiver becomes dormant, doing nothing until an app sends another matching broadcast.This chapter describes broadcast receivers in more detail.
This chapter’s first example contains the world’s simplest broadcast receiver. To be precise, Listing 4-1 contains the receiver class (MyReceiver, which extends BroadcastReceiver), Listing 4-2 contains code to broadcast to the receiver, and Listing 4-3 contains the example’s AndroidManifest.xml file.
Listing 4-1: A Simple Broadcast Receiver
package com.allmycode.rec1; ...
Read now
Unlock full access