Introduction
In this blog, we will look into Android Activities. When we launch an Android app, a user interface (UI) appears on our screen. That screen is known as an Activity. We will see the different kinds of activities that can be created using Android Studio.
In this article, we will be using the Android Studio application, so in case you haven’t yet set up the application on your system, you can check out this article.
Activity
An activity is a critical component of the android operating system. In layman’s terms, an activity is a screen with which the user interacts. This activity displays the user interface of our application. There are a lot of activities that you can create in the android studio, which are as follows:
- No Activity
- Basic Activity
- Bottom Navigation Activity
- Empty Activity
- Fullscreen Activity
- Google AdMob Ads Activity
- Google Maps Activity
- Login Activity
- Primary/Detail Flow
- Navigation Drawer Activity
- Settings Activity
- Scrolling Activity
- Tabbed Activity
- Fragment + ViewModel
- Native C++
No Activity
No Activity, as the name implies, means starting a new empty project.
When you choose No Activity, no files are created automatically. Therefore, there will be no XML or Kotlin files when this activity is selected. The file structure of the project will look like this:
Basic Activity
On selecting the Basic Activity, a new activity is created with the navigation component. It contains a menu button and a floating action button. Following files are created upon selecting a basic activity:
Bottom Navigation Activity
As the name suggests, Basic Navigation Activity creates an activity with a bottom navigation bar. You might have come across some apps that contain a navigation bar at the bottom. Instagram is one such example. Upon selecting this activity, a welcome page is created which looks something like this:
Empty Activity
Empty Activity is one of the most frequently used activities while making an android project. It creates new empty activities. The welcome page created upon selecting an Empty Activity looks something like this:
Fullscreen Activity
Upon selecting a Fullscreen Activity, a new activity is created, which toggles with the visibility of the system user interface. Many document reader apps use a full-screen activity to show slides or files in full screen for a better view. The welcome page of a fullscreen activity looks something like this:
Google AdMob Ads Activity
Google AdMob Ads Activity is used to add advertisements to the app. This is helpful when you wish to generate extra revenue for your app by using ads. There are four different ways you can attach an ad to your app, which are as follows:
- Banner: As the name suggests, it attaches the ad as a banner to the app.
- Native: Ads designed to fit the app
- Rewarded Video: It is a widespread way of attaching an ad. It provides the user with some rewards for watching. This type of attachment is widely used in movie/web series streaming apps.
- Interstitial: Full-screen ads can be attached using this method.
Using the Google AdMob Ads Activity, a new activity is created with an AdMob Ad fragment.
Google Maps Activity
By using a Google Maps Activity, a new activity is created, which has google maps integrated into it. It can be used to track a location or show a path on the map etc. You can also customize Google Maps in your application according to your requirements.
Login Activity
Login Activity creates a new activity with a basic login/register page. It contains an Email and a password field. More fields can be added as per the requirements of your application. It is the most widely used activity, and almost every app has this activity as its first page. Upon creating a login activity, the following welcome page is created:
Primary/Detail Flow
A Primary/Detail flow is created upon selecting a Primary/Detail Flow Activity. It is generally used to display a collection of objects with their name and details. For a tablet-sized screen, this flow is presented using two columns, but for screens with smaller sizes, only one column is used to show the collection of objects and their details. A Master Fragment and a detailed fragment are the two activities created upon selecting this template.
Navigation Drawer Activity
This Activity can be used to create a sliding left menu, which can be used to display essential navigation links of the application. It is highly convenient while navigating from one link to another in the app. To use a Navigation Drawer Activity, the user generally needs to slide the screen from left to right or click on a floating action button.
Settings Activity
As the name suggests, the Settings Activity creates a basic layout for the settings of an application. Almost all smartphone devices have a settings application on the mobile.
Scrolling Activity
While reading a lengthy document on the device, sometimes you need to scroll a bit to read the rest of the file’s content. A Scrolling Activity creates a new activity with a scrolling feature which is highly useful in a such a case. It provides a vertical scrolling feature to the application.
Tabbed Activity
It is used to create an activity with tabs. Tabs are displayed horizontally, and upon clicking on a particular tab, users can move from one tab to another. This type of activity is quite common in social media applications. You might have used the Whatsapp app; the main page where tabs for chats, status, and calls are displayed is one example of this activity.
Fragment + ViewModel
Upon selecting the Fragment + ViewModel activity, a new activity is created with a fragment and a view model. A fragment provides an activity with a more modular design. It is used to encapsulate functionality, making it easier to resue withing different activities. View model basically serves as a connecting link between the View and the Model.
Native C++
Native C++ creates a project with an empty activity that is configured to use JNI(Java Native Interface). JNI describes a way for the Java/Kotlin Executed code to interact with the native code written in C/C++.