The Anatomy of an Android Application

All About activity, fragment, Intent, Broadcast Intent, Broadcast Receivers, and Android services

CodingwithSaud
The Startup
4 min readFeb 9, 2021

--

Photo by Joyce McCown on Unsplash

This article will provide an understanding of the high-level concepts at the back of the architecture of Android applications. We will see in detail at the two different components that can be used to create an application and the mechanisms that work together to create a unified application.

1. Activities in Android

Those who know Object-oriented languages can understand the concept of encapsulating the elements of application functionalities and then used as objects to creating and manipulating the application. Since Android applications developed in Java and Kotlin. So Android architecture also has the concept of reusable components to the higher level.

Android application is developed by one or more components that work together, these components are activities. Activity is a single and independent module that is correlated to the application’s single screen and its functionalities.

For example, a Job finder application has an activity that will display the list of available jobs for the current day. The application might have another activity that will take professional details of candidates.

An Activity is a completely reusable and interchangeable component of an application that can be intended from other applications. Rather than making a new Activity for sending the email in the new application, a developer can call or intend the email activity of an existing application like Gmail, outlook, or yahoo.

Each time activity that is display will be created as a subclass of the Activity class which comes from Android. So Each activity is called independently, activity didn’t depend on a specific type of application flow it is completely independent and can be intended directly.

The Activity cannot be using its instance and one activity can’t call directly any method or use instance data of other activity. So Instead of this, you should use Intent and Content Providers.

Activity can’t give the results to another activity from which it intended or invoked. If you want to get results from the invoked activity, so you must invoke it as a sub-activity of originating activity.

Photo by Denys Nevozhai on Unsplash

2. Fragment in Android

As I describe above activity is a single user interface with a layout design file and a java class for dynamic functionalities. One way to make Android apps by using the activities as required screens. But it is good to make a different section in the activity layout. So that it is easy to categorize user interface and it reduces the coupling and increases the separation of the concern in the app coding. The fragment represents a separate part of a user interface or activity layout or any other layout. So we can use fragments as a separate section in an activity layout. An activity can become just a container of the different fragments with different layouts. It is preferable to create a single activity that switches between different fragments as a different screen in the app.

Photo by Piotr Wilk on Unsplash

3. Intent in Android

The intent is a built-in class from android SDK which is used to launch another activity from one activity and using intent we can implement a flow of activities that can make a complete application. Intent can contain the data about the operation to be performed and data which is passing from one activity to another activity.

There are two types of intent.

  1. Explicit Intent
  2. Implicit Intent

1. Explicit Intent

It will specify which application or package name fully satisfies the intent. For example, if you want to open a specific application or you want to open another application.

2.Implicit Intent

It will not specify the name of any component but instead of it, it will use general action to perform. For example, you want to show the specific location on the map so you can use implicit intent with a specific action, and which app qualifies for it will be selected.

--

--

CodingwithSaud
The Startup

I’m a good husband, father and Senior Developer.