Pages

Monday, January 17, 2022

Handlers and Threads In Android Studio

 When a user opens an application android operating system creates a process or a thread of execution of commands called the main Thread or the ui thread . The  main thread is nothing but handler thread .The main thread is responsible for handling events from all over the apps . Any piece of java code is that needs to be exwcuted are pushed and serviced by the Main Thread .The main is thread is doing most of the stuff so its better to use multiple thread other than the ui thread or main thread. 


A thread is the path followed when  executing a program .The jvm allows and application to have multiple threads of execution running parralell . So multple path of programs can executed in paraalel .so as to bring the results or returns of methods to the Main Thread


We can perform any task in multiple threads but as far as  Updating the userinteface or anything updating the main thread is concerned we cant do it unless we have handlers in that thread that will tell the Main Thread about the updates or data .



A video will be uploaded soon with the attachment 



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 


KeyPoints-Series-1

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