dcsimg
November 19, 2017
Hot Topics:

Android Studio Tutorial: An Introduction

  • December 21, 2016
  • By Joydip Kanjilal
  • Send Email »
  • More Articles »

Android is one of the most popular mobile device platforms. The Android platform allows developers to write managed code using Java (http://www.developer.com/java) to manage and control the Android device. Android Studio is a popular IDE developed by Google for developing applications that are targeted at the Android platform. Note that Android Studio has replaced Eclipse as the IDE of choice for developing Android applications. This article presents a discussion on how to get started using the Android Studio for developing Android applications.

Android Studio, the Full-blown IDE for Android Development from Google

Android Studio contains tools such as the Android Virtual Device Manager and the Android Device Monitor. It also contains Gradle, which helps you configure your Android application seamlessly. Some of the interesting features of Android Studio include the following:

  • Support for a fast emulator
  • Support for Gradle
  • Support for plenty of code templates and GitHub integration
  • Support for Google Cloud Platform
  • Support for template-based wizards for creating Android designs and components
  • Support for rich layout editor
  • Support for deep code analysis
  • Support for extensive set of tools and frameworks

Creating an Android Application Using Android Studio

Assuming that Android Studio is installed in your system, we will explore how we can create a simple application using Android Studio in the section. Android applications are based on the Java programming language and make extensive use of XML. To create an Android application using Android Studio, follow these simple steps:

  1. Start Android Studio in your system.
  2. Click "Start a new Android Studio project," as shown in Figure 1.

    Studio1
    Figure 1: Starting a new project

  3. In the "New Project" dialog that pops up next, specify the application name and company domain.

    Studio2
    Figure 2: Specifying the application and company domain

  4. Click Next to proceed.
  5. In the next screen, "Select the form factor your app will run on", check "Phone and Tablet."

    Studio3
    Figure 3: Selecting the form factor

  6. Specify the SDK version you want to use.
  7. Click Next.
  8. In the next screen, "Add an activity to Mobile", select "Empty Activity."

    Studio4
    Figure 4: Selecting "Empty Activity"

  9. Click Next.
  10. In the next screen, "Customize the Activity," specify the activity and layout name.
  11. Click Finish when done.

That's all you need to do for now. Please be patient for a while because it would take some time for the project to be loaded. After a while, your first Android application will be created—default though, because it doesn't have any custom code.

Let's dig into a bit of code now. You can create user interfaces in Android applications using Java or XML. Let's write some Java code to display a text message to the user. Refer to the class named MainActivity that was created by default. This class is created in the file named MainActivity.java and extends the AppCompatActivity class and contains the onCreate method. Note that any Android application can have one or more activities. An activity usually represents a screen. An activity may be defined as the visual representation of your Android application.

public class MainActivity extends AppCompatActivity {
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      // You can write your own custom code here
   }
}

Replace the default code of the onCreate method with the following:

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      TextView textView = new TextView(this);
      textView.setText("Hello, this is my first Android
         application!");
      setContentView(textView);
   }

To run the application, press "Shift + F10". When you run the application, here's what the output would look like.

Studio5
Figure 5: The finished application, running its output

Summary

Android Studio is a development IDE from Google that makes your life easier for developing Android applications. This article presented a discussion on how to get started using the Android Studio to build and develop Android applications. I will discuss more on developing Android applications using Android Studio in my future articles here. Happy reading!

References






Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date