Tagbangers Blog

The Basic of the Basics: Android Studio

Hi, I'm Kakizoe and this is my first year in Tagbangers. Since last year I have been developing apps for Android, and I recently started to realize how fun it is.

In this article, I'd like to review the basic concepts of Android apps, and also to share a few things you should know when writing a program. The following is the list of things that will be discussed in this article:

  • The Layout files and Class files in Android Apps.

  • Activity and Fragment

  • Dealing with Cache

  • A Useful Shortcut Key

  • The Layout files and Class files in Android Apps

The screen of an Android app consists of two main parts: the "Layout File" and the "Class File".

The Layout File is a file for elements that get displayed on the screen, such as texts, images, and buttons. There are two ways for a Layout File to be generated: 1. Write with XML and 2. Generate from a Java code.

The Class File is a file that processes any movements on the screen, such as tap or scroll, with a Java code. It can also be separated into two files called "Activity" and "Fragment".

  • Activity and Fragment

These two are extremely important when developing an Android application.

An Activity is a class file that holds a window of a smartphone, display the texts and images generated by the layout file, and responds to the user's touch of the screen. Since only one activity can be displayed per screen, when transitioning from one activity to another, the screen also switches.

For each activity, there can be multiple Fragments. Therefore something that is implemented in a single activity can be separated into multiple fragments. When using fragments you usually follow these 3 steps:

1. Create a class for a fragment

2. Create a layout file to use to construct the view of a fragment

3. Call the fragment from an activity

To make it easier to understand, Activity is like a drawer without anything in it, and Fragments are the shirts, pants, jackets, etc. that goes into the Activity drawer.

  • Dealing with Cache

When writing a code in Android Studio, sometimes the code suddenly turns red.

You might think that's because there's something wrong in the code, and you're right...most of the times. Sometimes, that is not the case. 

There could be errors even if the code is absolutely correct. 

How can that happen?

Well apparently, caches can cause errors in your code. There are 3 ways to prevent this.

1. Clear your cache by selecting "Gradle"→"app"→"clean".

2. Go to "File" and select "Invalidate Caches/Restart" to clear the cache or restart.

3. Go to "Build", then select either "Clean Project" or "Rebuild Project".

  • A Useful Shortcut Key

Since Android Studio was made based on IntelliJ IDEA, once you master the shortcut keys for either one of the them, you'll be able to boost your productivity in both softwares. Unfortunately I haven't yet memorized all the shortcut keys, but there's this one very useful shortcut key, so I'd like to share it with you. And the key is...

Command + Shift + F

Suppose that you downloaded some kind of source code and wanted to know how a specific code works.

That's when you wanna use this shortcut key. This key allows you to search how a specific code is being used through the whole code inside a project.

Before I knew about this shortcut key, I used to go through lines of code guessing which code is used. This was a very inefficient method. Once I started using this shortcut, I was able to boost my productivity and have a better understanding on program flow.

Original article written by: Wataru Kakizoe

Translated by: Yu Koga