First Android Program

Begin your journey of developing Android apps, with coding your first Android program in Android Studio. Following the below steps, easily create a basic demo app.

Learn how to setup Android Studio for Android app development.

Let’s begin the step by step procedure, to work with our first Android program,

Step– Go to Start and type Android Studio, search and click on it as shown below,

Find Android Studio

Step- After clicking, Android Studio will open. Now, you need to click on File > New > New Project,

Android New Project

Step- A new dialog box opens up, here add the project name, package and the following information about the app,

  • Application name: Enter the application name here
  • Package name: Enter the package name here
  • Project Location: The project location i.e. path

We added ExampleApplication as Application name and Package name as com.studyopedia.exampleapplication,

Android Project name

Step- After clicking Next above, you will reach the following section, wherein set the Minimum SDK. Here also set the SDK for multiple devices such as Phone and Tablet, Wear, TV, and Android Auto.  We will be only selecting SDK for Phone and Tablet,

Target Android Devices

Step- After clicking Next above, you need to select the activity type. We’re creating a simple demo application, so we’ll go for Empty Activity,

Android Empty Activity selected

Step- Add the activity as well as the layout name. Here, we’re keeping it the default, Activity Name as MainActivity and Layout Name as activity_main.

After that click Finish,

Android Activity Name

Wait for some time to load the newly create project. This created the project and updates the Gradle Build Information.

The project directory is visible with MainActivity.java, activity_main.xml, and other files.

Here’s the code for both the files,

MainActivity.java

The src\main\java\com\studyopedia\studyopediaapplication\MainActivity.java is a java class which sets the views. Here we will set the View to be displayed with the setContentView.

Through this, Set the main layout as your main content view,


activity_main.xml

For src\main\res\layout\activity_main.xml,

Here, we have added a text, and hardcoded the string as done in the Android Project Directory lesson, under strings resources,

strings.xml


AndroidManifest.xml

The content of \src\main\AndroidManifest.xml, provides key information of your app to the system. The system needs this to run your code,

We created an AVD in the Setup Android Environment lesson, so now we will run our project using the same AVD on Emulator.

Here are the steps,

Step: Go to Run > Run app

Run Android app

Step: Now, the list of Available Virtual Devices will be visible. Right now we have only a single device, so click on it and press OK,

Available Android Virtual Devices

The AVD will start and the emulator is now visible with the output.

First Android Program output


If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


For Videos, Join Our YouTube Channel: Join Now


Understanding Gradle
Android Layouts
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading