The Wayback Machine - https://web.archive.org/web/20240917094038/https://www.geeksforgeeks.org/android-running-your-first-android-app/
Open In App

Android | Running your first Android app

Last Updated : 05 Apr, 2021
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

After successfully Setting up an Android project, all of the default files are created with default code in them. Let us look at this default code and files and try to run the default app created.

  • The panel on the left side of the android studio window has all the files that the app includes. Under the java folder, observe the first folder containing the java file of your project.
    android 7
    For every activity, a “.java” file and a “.xml” file is created. In this case for MainActivity, “MainActivity.java” and “activity_main.xml” are created.

    The above java file shows us the default code that is present when an app is created. An activity is created that extends AppCompactActivity class.

    The “res” folder contains “layout” subfolder, which includes the xml files of the projects.

    android8

    You can find the activity_main.xml file under the layout folder. This the XML file corresponding to the MainActivity. There is an onCreate function that overrides a function of AppCompactActivity class. onCreate(Bundle) is where you initialize your activity. When the activity is first started, then both onCreate() methods are called. But after the first start of Activity, the onCreate() of application will not be called for subsequent runs.

  • Now, consider the activity_main.xml file, it contains various tags similar to HTML. The first tag ensures the version. The second tag is usually the Layout tag. There are various types of Layouts but for now, let us go with the default RelativeLayout. This is a layout that places the widgets relative to screen size.

    There is a TextView widget by default. This “TextView” is basically the Text field that displays the text specified. It has various attributes. For now, consider the default attributes present. The layout_width and layout_height are the width and height of the widget occupied in the screen. The attribute “wrap_content” refers to width or height being restricted to the content of the text.

    The text attribute takes a string in quotations ( i.e., “ ” ). The content within this is displayed on the screen.

    android 9

    Now, click the “Run” option at the Toolbar at the top. You can observe the option being highlighted in the image below.

  • You would get a pop-up as in the image below.
    android 10
  • You can either choose the emulator or you can connect your phone and find them listed under Connected Devices but for this you must enable the developer options in your phone and set the USB debugging mode on.
    android 11
    Once done, click on OK.
  • Usually, the emulator consumes a lot of RAM. The more RAM size you have, the faster your emulator will work. Generally, 4GB is the descent RAM size. Size more than that would increase the performance of your emulator.

    The image below shows the working of the first app, My Application. You can find all the basic functionalities that your phone has, on the emulator, like Home button, back button, power, etc.
    android 12


Previous Article
Next Article

Similar Reads

Fix "Error running android: Gradle project sync failed. Please fix your project and try again" in Android Studio
In this article, we will see how to fix the error: "Gradle project sync failed. Please fix your project and try again" in Android Studio". Before getting into the solution part, let's discuss Gradle. What is Gradle? Gradle is an open-source build automation tool that automates the creation of applications. The various steps involved in creating an
5 min read
Java For Android - Building Your First Android App
Android app development can play a major role in writing the app functionalities using Java programming. Every activity can be designed with Java programming. Android apps are developed using the Android Studio IDE, which provides the environment for Java development for Android programming. PrerequisitesJava ProgrammingAndroid Studio in your syste
5 min read
Android Java Projects - Build Your First Android App from Scratch
Are you eager to boost your Android development skills and create cool projects? Our blog post, "Android Java Projects," is here to help! Whether you're just starting your software development career or want to add good projects to your CV then, working on real projects is the best way to learn and grow as a developer. In this post, we've gathered
6 min read
How to Dismiss Running App Notifications in Android 13?
You may be accustomed to seeing the default notifications which every running app shows you while it is running on your device, like your watch companion app, or any other app, which shows you notifications, but that is history now, as from Android 13, those notifications can be just simply swiped like any other normal notification. This could be a
4 min read
How to Share Text of Your App with Another App and Vice Versa in Android?
Most of the time while using an app we want to share text from the app to another app. While using Many Social Media Platforms we find this feature to be very useful when we want to share information from one app to another. The Android intent resolver is used when sending data to another app as part of a well-defined task flow. To use the Android
5 min read
How to Share Image of Your App with Another App in Android?
Most of the time while using an app we want to share images from the app to another app. While using Many Social Media Platforms we find this feature to be very useful when we want to share information from one app to another. The Android Intent resolver is used when sending data to another app as part of a well-defined task flow. To use the Androi
4 min read
Different Ways to fix "Error running android: Gradle project sync failed" in Android Studio
Gradle is one of the most important components of Android apps. It handles all the backend tasks and manages all the external dependencies which we will be going to use in building our Android Application. Sometimes due to any issue or after formatting of your pc. Some of the Gradle files may get deleted unexpectedly. So when you will start buildin
3 min read
How to Filter Logcat to Only Get Messages From the Running Application in Android?
In Android Studio Logcat is a window to display messages, Logcat shows real-time messages and keeps history for the future. To see the messages of users' own interests users can filter Logcat cat. The default filter is set to log output related to recent ran apps only. To view Logcat follow these steps View > Tool Windows > Logcat To Filter L
1 min read
How to Keep Android Apps Running Smoothly?
This article is all about creating a better Android app (no more lags!) and building a smooth-running interface. We will discover how to increase the performance of an Android application. First and foremost, we must determine one big question: Why does the Android App slow? or Why does an Android app lag? We will begin with the themed culprit behi
4 min read
How to Fetch Currently Running Tasks in Android Programmatically?
Android devices run several tasks in the background for providing a seamless experience to the users. Importantly, tracking background and foreground usages is important as it directly impacts the battery life and static memory, i.e. RAM. One can enable the developer option in the settings to track all the background tasks and services. However, on
2 min read
Running User Interface Thread in Android using Kotlin
User Interface Thread or UI-Thread in Android is a Thread element responsible for updating the layout elements of the application implicitly or explicitly. This means, that to update an element or change its attributes in the application layout ie the front-end of the application, one can make use of the UI-Thread. Realizing UI Thread: For example,
4 min read
How to Integrate In-App Review API into Android App?
Once we publish our app over the PlayStore and as it became live there, app rating and reviews become very crucial to driving audience and downloads to your app. In order to increase this, we ask our users to rate the app through a popup window and redirecting them to the PlayStore. But this nowadays creates little problems, once users went to Play
3 min read
7 Major Reasons Why Your Android App is Performing Slow - Must Read For Developers!
"Nothing worse than a laggy slow app!". Laggy apps deliver bad experiences to users. It’s true that most of the end-users can’t wait to get a response from a mobile app. The absolute loading time for a mobile app is about two seconds. Still, according to research by Akamai research, for every extra second that the app consumes, the conversion rate
5 min read
How to Add Fingerprint Authentication in Your Android App without Using any Library?
Biometric Fingerprint authentication is one method of protecting sensitive information or premium content of your app. Nowadays, all payment apps use this feature in their app. It is very easy to implement. A sample Video is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project us
6 min read
How to Check if Application is Installed in Your Android Phone and Open the App?
In this article, we are going to check if a particular app is installed on our phones or not. If yes then we will be having an option to open the app. Else it will show a toast message saying Not available. So here we are going to learn how to implement that feature. Note that we are going to implement this project using the Java language. Step by
3 min read
How to Add SHA Fingerprints For Your Firebase Android App?
In the field of cryptography, SHA-1 (Secure Hash Algorithm 1) is a hash function that accepts an input and generates a 160-bit (20-byte) hash value known as a message digest, which is commonly represented by 40 hexadecimal digits. Despite being cryptographically weak, SHA-1 is still frequently used. You must supply the SHA-1 of your signing certifi
2 min read
Receive Rich Content in Your App on Android 13
Android 13 brings to us a plethora of new services, APIs, features, and functions to add to our app to turn the overall user experience more delightful than ever. Starting in this release there have been introductions to even richer content and the inclusion of newer file types which one can include in their apps to get more insights and drive more
4 min read
How to Implement Google AdMob in Your Android App?
In order to earn money from the Android app or game, there are several ways such as in-App Purchases, Sponsorship, Advertisements, and many more. But there is another conventional approach to earning money from the Android app is by integrating an advertisement which is known as Google AdMob. Google AdMob is created with developers in mind, AdMob h
4 min read
How to Integrate Google Forms in Your Android App Without Using WebView?
Sometimes we have to set some type of form to send the data to our backend this can be any type of form, it can be a contact form or some kind of support form but there is no kind of tool that is provided by Android and other tools require Web View or paid to implement itself so in this article we are going to integrate Google Form in our android a
6 min read
How to Ban an Android Device from Login to Your App?
First of let's understand what is device ban feature device ban feature in Android allows administrators/developers to restrict specific devices from accessing an application or service. This is crucial for maintaining security and enforcing policies. Why Device Bans are Important?Let's take an example you have created a social media application an
6 min read
How to Add Fingerprint Authentication in Your Android App?
Now a day, we have seen that most of our Android phone contains fingerprint authentication. And we can implement that fingerprint authentication in our app so to secure our app as much as we can. In this article, we will take a look at the implementation of fingerprint authentication. What we are going to build in this article? We will be building
4 min read
How to find your Wi-Fi password on your Android phone
How to find your Wi-Fi password on your Android phoneIf you're like most people, you probably kept the random password on the bottom of your home router. That random password is safe, but it's not easy to remember. If you already have your login details on your Android phone or tablet, there's no need to dust off and flip over your gateway. This gu
8 min read
Running Background Tasks in Flutter
Creating an application that is able to handle processes with background capabilities is crucial for numerous applications, including geolocation, music, or other processes which may take a lot of time. Flutter, an open-source UI toolkit owned by Google lets developers write and compile applications for mobile, web, and desktop all at once. In this
6 min read
How to Add Audio Files to Android App in Android Studio?
The audio file format is a file format for saving digital audio data on a computer system and all are aware of audio files. So in this article, we are going to discuss how can we add audio files to the android app. There are three major groups of audio file formats: Format Name Description Examples Uncompressed audio formatsUncompressed audio forma
3 min read
Different Ways to Analyze APK Size of an Android App in Android Studio
APK size is one of the most important when we are uploading our app to Google Play. APK size must be considered to be as small as possible so users can visit our app and download our app without wasting so much data. In this article, we will take a look at How we can analyze our APK in Android Studio to check the APK size. Android Studio itself pro
3 min read
How to Build a Number Shapes Android App in Android Studio?
Android is a vast field to learn and explore and to make this learning journey more interesting and productive we should keep trying new problems with new logic. So, today we are going to develop an application in android studio which tells us about Numbers that have shapes. We will be covering two types of numbers i.e. triangular and square. So, f
4 min read
How to Build Binary to Decimal Converter Android App in Android Studio?
This app will convert a Binary Number into a Decimal Number. Some people may also have written a java program to convert a Binary Number into a Decimal Number, but while making an app let's see how to do that. Brief Go Through We will start by creating a new project with an Empty Activity. After creating a project, we would add the drawable resourc
5 min read
How to Use Stack Overflow to Fix Errors During Android App Development in Android Studio?
Stack Overflow, the life savior of developers, feels like Stack Overflow is built for the developers, by the developers, of the developers. According to Wikipedia: "Stack Overflow is a question-and-answer site for professional and enthusiast programmers". So being a developer or programmer can you imagine your life without Stack Overflowâ€Ķ. ? Most p
4 min read
How to Make a Scientific Calculator Android App using Android Studio?
The calculator is the app that is present on every android device. This app comes pre-installed or we can also install another application from Play Store. It is one of the most used applications for college students for making any calculations. In this article, we will take a look at building a simple scientific calculator app in Android using Kot
13 min read
How to Convert Any Website to Android App in Android Studio?
Here, we are going to make an application for the "GeeksForGeeks" website. By making this application we will be able to learn how we can convert a website to an Android Application just by following simple steps. You can use this concept for your personal website too and learn something new. What we are going to build in this article? In this appl
12 min read
Article Tags :