Android Application Component — Detail Explanation

App components are the essential building blocks of an Android app

https://cdn-images-1.medium.com/max/1600/1*87pdEP5hAXA9JQvzXjOTSA.png

https://medium.com/@Abderraouf/understand-android-basics-part-1-application-activity-and-lifecycle-b559bb1e40e

There are four different types of app components:

1- Activities2- Broadcast receivers.3- Services.4- Content providers.

Activities

Broadcast receiver

For example,

i) When mobile is 100% charged then system show dialog of remove charger is one kind of broadcast receiver which trigger on 100% charged state.

ii) Applications can register for the ACTION_BOOT_COMPLETED system event which is fired once the Android system has completed the boot process.

For instance, Android system sends broadcasts when system events occur such as system boots up, device starts charging, connectivity chaning, date chaning, low battery. Furthermore, apps can send custom broadcasts to notify other apps(data download completed).

There are two ways to declare a receiver:

The registration is done in the manifest file, using <register> tags.

Firstly, specify the receiver in your manifest file.

<receiver
 android:name=".MyBroadcastReceiver"android:exported="true"> 
<intent-filter> 
<action android:name="android.net.conn.CONNECTIVITY_CHANGE""/> 
</intent-filter>
</receiver>
public classMyBroadcastReceiver extendsBroadcastReceiver {
 @Override public void onReceive(Context context, Intent intent) { 
    Toast.makeText(context, "Intent Detected.", Toast.LENGTH_LONG).show(); 
  }
}