Broadcast Receiver


 

  1. Static Register
  2. Dynamic Register
  3. Using LocalBroadcastManager
  4. Using WakefulBraodcastReceiver
  5. BraodcastReceiver Order

 

1. Static Register
Step 1 :Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, MyReceiver.java and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

ScreenShot:

boardcast boardcast2

Download SourceCode

 

2. Dynamic Register

Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.

Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, MyReceiver.java and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

Step 6 : Open build.gradle(Module: app) and add following code :

ScreenShot:

broadcast_dynamic

Download SourceCode

 

 

3. Using LocalBroadcastManager

Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.

Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, MyReceiver.java and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

Step 6 : Open build.gradle(Module: app) and add following code :

ScreenShot:

 localbroadcastmanager

Download SourceCode

 

4. Using WakefulBraodcastReceiver

Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.

Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, MyReceiver.java and add following code:

Step 5 : Open src -> package -> Create new class, SimpleWakefulService.java and add following code:

Step 6 : Open AndroidManifest.xml and add following code :

Step 7 : Open build.gradle(Module: app) and add following code :

ScreenShot:

wakefulbroadcast wakefulbroadcast3 wakefulbroadcast2

Download SourceCode

 

5. BraodcastReceiver Order

Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.

Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, MyFirstReceiver.java and add following code (Note: Create two more BroadcastReceiver class for this example, they similar to MyFirstReceiver class, except the name in the toast.):

Step 5 : Open AndroidManifest.xml and add following code :

Step 6 : Open build.gradle(Module: app) and add following code :

ScreenShot:

 broadcast_order broadcast_order2 broadcast_order3

Download SourceCode