Posts

Showing posts with the label Broadcast Receiver

Custom Broadcast

Image
This example will show how you can send and receive the broadcast from your application. Steps : 1) For sending the broadcast from your application you can use sendBroadcast() method. 2) To receive that broadcast you need to add the receiver to the manifest file. 3) Create the broadcast receiver that will handle the broadcast send by your application and do exactly what you want. 1) Sending broadcast from your application:-   Main.java public class MainActivity extends AppCompatActivity {      protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);         Intent i = new Intent();         i.setAction("Mybrodcast");              //You can set any action name instead of Mybrodcast suitable to your application         i.putExt...