How to Create Constructor, Getter/Setter Methods and New Activity in Android Studio using Shortcuts?
Last Updated :
18 Feb, 2021
Android Studio is the official integrated development environment for Google’s Android operating system, built on JetBrains’ IntelliJ IDEA software and designed specifically for Android development. In this article we are going to discuss the following three things:
- Create a Constructor for Class in Android Studio using Shortcuts
- Create a Getter/Setter or both for Class in Android Studio using shortcuts
- Create a new activity in Android Studio using shortcuts
If you are new to Android Studio then to know about How to start Creating a basic Project in Android Studio. Refer To Android | Running your first Android app.
Create a Constructor for Class in Android Studio using Shortcuts
Constructors are used to initializing the state of an object. Like methods, constructors also contain a collection of statements(i.e. instructions) that are executed at the time of Object creation. Here, you will learn How to create a constructor without typing commands.
Step 1: Make sure your cursor is within the class. Right-click using your mouse and then select Generate as shown in the below image.

Step 2: Then, Click on the Constructor.

Step 3: Highlight all using Ctrl + A and then click on OK. You have created a constructor for your class.

Create a Getter/Setter or both for Class in Android Studio using shortcuts
Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that binds together code and the data it manipulates. Another way to explain encapsulation is to think like, it is a protective shield that prevents the data from being accessed by the code outside this shield. Here, you will learn How to create getter/setter or both without typing commands.
Step 1: Make sure your cursor is within the class. Right-click using your mouse and then select Generate.

Step 2: Then, Click on Getter/Setter/Getter and Setter according to your choice.

Step 3: Highlight all using the Ctrl + A and then Click on OK. And You are Done.

Create a new activity in Android Studio using shortcuts
Generally, when a developer wants to create a new project in the android studio he/she needs to select a project template which is consisting of many activities as shown in the below image. (Considering that the developer developing the android app for phone and tablet).

Note: To know more about the above activities please refer to Different Types of Activities in Android Studio.
So when you are developing a project and if there is a need to include a different activity in your project then you may follow the following steps.
Step 1: Right-click on the First button inside java (your app’s package name), then click on New.

Step 2: Then Go to Activity > Empty Activity (The next step is to choose the Activity type. Activity in Android refers to a single screen with a user interface. For Beginners, “Empty Activity” is recommended. ). Click on Empty Activity.

Step 3: Now, A new Dialog Box will appear. Then, fill in the Activity Name text field. In Android studio, files named in CamelCase are preferred. An XML file is used to provide functionalities of the user interface for our app. An XML file of the activity is created using the first word in the Activity name. Click on Finish. And you have created your activity.

Similar Reads
How to Create Admin & Client App in One Project Using Android Studio?
You all must know about projects in which two applications are required one for the client and the other for the admin. Here we will see how we can implement both the applications under a single project in android studio. Let us see the step-by-step implementation of this procedure. Step by Step Imp
2 min read
How to Capture a Screenshot and Screen Recording of an Android Device Using Android Studio?
Android Studio is the official IDE (Integrated Development Environment) for Android app development and it is based on JetBrainsâ IntelliJ IDEA software. Android Studio provides many excellent features that enhance productivity when building Android apps. Whenever we are developing an app and in tha
2 min read
How to Create Your Own Shortcut in Android Studio?
Android Studio is the official integrated development environment for Googleâs Android operating system, built on JetBrainsâ IntelliJ IDEA software and designed specifically for Android app development. Android Studio offers a lot of shortcuts to users. It also provides to configure Keymap and add y
2 min read
How to Create/Start a New Project in Android Studio?
After successfully installing the Android Studio and opening it for the first time. We need to start with some new projects to start our journey in Android. In this article, we will learn about How to Create a New Project in Android Studio. Steps to Create/Start a New Android Project in Android Stud
2 min read
Send Multiple Data From One Activity to Another in Android using Kotlin
There are multiple ways for sending multiple data from one Activity to Another in Android, but in this article, we will do this using Bundle. Bundle in android is used to pass data from one activity to another, it takes data in key and value pairs. To understand this concept we will create a simple
3 min read
How to Create New Package Inside Src Folder in Android Studio?
A package is a namespace that combines a set of relevant classes and interfaces. Conceptually one can consider packages as being similar to various folders on your computer. One might have HTML pages in one folder, images in another, and scripts or applications in yet another. Because in android, so
2 min read
How to Create a New Fragment in Android Studio?
Android Studio is the official integrated development environment for Google's Android operating system, built on JetBrains' IntelliJ IDEA software and designed specifically for Android development. You can Develop Android App using this. Here, We are going to learn how to create a new Fragment in A
2 min read
How to Create Google Sign In UI using Android Studio?
Nowadays, android apps are very popular. This UI has generally seen in the âGoogle Sign Inâ App. In this article, we will create a Google Sign UI in Android. Below are the various steps on how to do it. This will help the beginner to build some awesome UI in android by referring to this article. St
3 min read
10 Important Android Studio Shortcuts You Need the Most
Android Studio is the official integrated development environment (IDE) for Android application development. In this article, some of the most imp shortcuts are explained in Android, with the help of examples. Some of the most important Shortcut keys used in Android Studio are: 1. CTRL + E -> Rec
3 min read
Start a New Activity using Intent in Android using Jetpack Compose
In Android OS, an Intent is a mechanism used to navigate a user to another activity or application to achieve a specific task. In general, Intents are used to progress to the next activity or come back to the previous activity. In this article, we will show you how you could start a New Activity usi
4 min read