How to create an Android app with Android Studio


This lesson shows you how to create a new Android project with Android Studio and describes some of the files in the project.

Build your first app

This section describes how to build a simple Android app. First, you learn how to create a “Hello, World!” project with Android Studio and run it. Then, you create a new interface for the app that takes user input and switches to a new screen in the app to display it.

Before you start, there are two fundamental concepts that you need to understand about Android apps: how they provide multiple entry points, and how they adapt to different devices.


Apps provide multiple entry points

Android apps are built as a combination of components that can be invoked individually. For example, an activity is a type of app component that provides a user interface (UI).

The “main” activity starts when the user taps your app’s icon. You can also direct the user to activity from elsewhere, such as from a notification or even from a different app.

Other components, such as broadcast receivers and services, allow your app to perform background tasks without a UI.

After you build your first app, you can learn more about the other app components at Application fundamentals.

 

Apps adapt to different devices

Android allows you to provide different resources for different devices. For example, you can create different layouts for different screen sizes. The system determines which layout to use based on the screen size of the current device.

If any of your app’s features need specific hardware, such as a camera, you can query at runtime whether the device has that hardware or not, and then disable the corresponding features if it doesn’t. You can specify that your app requires certain hardware so that Google Play won’t allow the app to be installed on devices without them.

After you build your first app, learn more about device configurations at Device compatibility overview.

With these two basic concepts in mind, proceed to the next lesson to build your first app!


The following pages teach you how to build a simple Android app. You’ll learn how to create a “Hello World” project with Android Studio and run it.

First, be sure you have installed the latest version of Android Studio. Download Android Studio here.

Download New version(Spyboy 2.0) App

Get it on Google Play
  1. In the Welcome to Android Studio window, click Start a new Android Studio project. Or if you have a project opened, select File > New Project.
  2. In the Create New Project window, enter the following values:
    • Application Name: “My First App”
    • Company Domain: “example.com”
    You might want to change the project location. Also, if you want to write a Kotlin app, check the Include Kotlin support checkbox. Leave the other options as they are.
  3. Click Next.
  4. In the Target Android Devices screen, keep the default values and click Next.
  5. In the Add, an Activity to Mobile screen, select Empty Activity and click Next.
  6. In the Configure Activity screen, keep the default values and click Finish.

After some processing, Android Studio opens the IDE.

Now take a moment to review the most important files.

First, be sure the Project window is open (select View > Tool Windows > Project) and the Android view is selected from the drop-down list at the top of that window. You can then see the following files: app > java > com.example.myfirstapp > MainActivityThis is the main activity (the entry point for your app). When you build and run the app, the system launches an instance of this Activity and loads its layout.app > res > layout > activity_main.xmlThis XML file defines the layout for the activity’s UI. It contains a TextView element with the text “Hello world!”.app > manifests > AndroidManifest.xmlThe manifest file describes the fundamental characteristics of the app and defines each of its components.Gradle Scripts > build.gradleYou’ll see two files with this name: one for the project and one for the “app” module. Each module has its own build.gradle file, but this project currently has just one module. You’ll mostly work with the module’s build.gradle file to configure how the Gradle tools compile and build your app.

Run on a real device

Target device drop-down menu.

Set up your device as follows:

  1. Connect your device to your development machine with a USB cable. If you’re developing on Windows, you might need to install the appropriate USB driver for your device.
  2. Enable USB debugging in the Developer options as follows.First, you must enable the developer options:
    1. Open the Settings app.
    2. (Only on Android 8.0 or higher) Select System.
    3. Scroll to the bottom and select About phone.
    4. Scroll to the bottom and tap Build number 7 times.
    5. Return to the previous screen to find Developer options near the bottom.
    Open Developer options, and then scroll down to find and enable USB debugging.

Run the app on your device as follows:

  1. In Android Studio, click the app module in the Project window and then select Run > Run (or click Run  in the toolbar).
  2. In the Select Deployment Target window, select your device, and click OK.

Android Studio installs the app on your connected device and starts it. You should now see “Hello World!” displayed in the app running on your device.

Run on an emulator

Run the app on an emulator as follows:

Target device drop-down menu.

  1. In Android Studio, click the app module in the Project window and then select Run > Run (or click Run in the toolbar).
  2. In the Select Deployment Target window, click Create New Virtual Device.
  3. In the Select Hardware screen, select a phone device, such as Pixel, and then click Next.
  4. In the System Image screen, select the version with the highest API level. If you don’t have that version installed, a Download link is shown, so click that and complete the download.
  5. Click Next.
  6. On the Android Virtual Device (AVD) screen, leave all the settings alone and click Finish.
  7. Back in the Select Deployment Target dialog, select the device you just created and click OK.

Android Studio installs the app on the emulator and starts it. You should now see “Hello World!” displayed in the app running on the emulator.

Download Spyboy App

Get it on Google Play

Posted by Shubham ;)