Pages

Wednesday, January 12, 2022

Broadcast In Android

 Broadcast Are such classes in android by which data can be transferred bwetween several app also some triggers can be developed to execute some functions. 

For Example 

        We can run our own methods when an android phone starts or whenever there is incoming call acutually we can say they are triggers for a code to be executed when a specified intent is alive inside the android operating system  

<intent-filter>
         <action android:name="android.intent.action.BOOT_COMPLETED">
         </action>
      </intent-filter>

the above intent can be declared in MANIFEST File and A broadcast Reciever onRecieve Method is executed whenever this intent is recieved 

CUSTOM INTENTS IN ANDROID

you can create custombroadcast intent tha twhen on recieve will execute functions
public void broadcastIntent(View view){
      Intent intent = new Intent();
      intent.setAction("com.tutorialspoint.CUSTOM_INTENT"); sendBroadcast(intent);
   }
Include above code in your mainactivity on a button click this will send a broadcast intent and can be recieve via create reciever and declaring in manifest 


No comments:

Post a Comment

KeyPoints-Series-1

  The Android architecture has the Main Thread AKA UI thread, which updates the UI after every  16ms  frame.