A deeper look into Android Studio

Jeff Winger Sebastian
7 min readFeb 16, 2018

--

Intro

Hello everyone and thank you for tuning in for the second blog post of three regarding the application of Android Studio. Before we divulge deeper into the mechanics and actual code of Android Studio lets recap the main ideas that we talked about from blog post one. The main idea that was stressed in blog post one was that this mobile application development industry is constantly growing and with the constant raise in applications getting downloaded yearly more and more programmers are starting to include mobile development within their projects. The other main thing I talked about was just the tip of the iceberg of the application Android Studio and very basic file folder structures that are given within the project. Now with that being said lets dive right into the deep end of this application.

Creating a project

The very first step whenever opening a new application and wanting to write code is the most obvious. That is creating a project. So how you do this is by going under file>new > create Project. After clicking these steps you will be asked to create the project name but you can also choose at the bottom of the creation page if you want to include C++ support or kotlin support for those more comfortable coding in C++. After that page comes android development page which there you can choose the target device you are planning to code for. Once created you can also add activities to your app such as navigation or google maps option that will automatically build this feature into your emulator. After choosing the activity you hit finish and viola you application is ready for you to code.

public class Registration extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registration);
}
}

After creating the project the main Java code as shown will be created and this is the backbone of the application which does the building of the emulator and the phone screen itself.

Some Important Features

Before I start showing you the GUI layout and the code behind it, I’m going to tell you a little about some features that if you don’t know about from the tutorials or off the top of your head that you should be well aware of. The first main feature that is probably the most important within this program is the emulator feature. This feature is located in the upper right section of the application with a little green plus beside it. This feature is huge because when you click on options beside the green button it lets you choose from a several of different phones or tablets along with dimensions of the emulator for designing purposes. Another way to look at the layout is simply by pulling the GUI screen from the bottom right and there will be little markers showing what target phone or tablet you’re designing for. The second nice feature is the espresso testing feature which is located under the run option then espresso testing. The reason this is a huge advantage for programmers is if you are like me designing test cases to test the GUI framework of your application is annoying and very tedious. With the espresso testing tool not only does it record every action that you are completing on your GUI through the emulator it also writes test cases based off of those actions!

The third feature that is very handy and I found is a huge bonus when coding in Android Studio is the “Instant Run Feature”. What this feature does is super basic in the fact that you can constantly be changing your code as the emulator is running and when you go back to the emulator it will automatically update all the new code you have written. This is a good feature because the basic launch of an emulator does take time and if you had to constantly restart the emulator every single time you are changing code it would become very frustrating and annoying. The final feature that is much more improved in this application than most is the GUI interface design tool.

GUI Interface

Palette Selection Layout

When clicking into the XML where you can design the front end of your application it will bring up a screen with the dimensions of your target phone and also this nice little Palette section where you will find every tool needed to build your GUI. The first thing you must choose is a Layout Design which you can choose between these eight options:

· Constraint Layout — view group that aligns children based on the constraints that you give each item

· Grid Layout — displays items in a two-dimensional, scrollable grid

· Frame Layout — screen that you can use to display a single view

· Linear Layout (Horizontal) — view group that aligns all children in a single direction horizontally

· Linear Layout (Vertical) -view group that aligns all children in a single direction vertically

· Relative Layout — view group that displays child views in relative positions

· Table Layout — view that groups views into rows and columns

· Table Row — view that groups views into rows

The main layout that is most commonly used and the one I’m going to focus on is the relative layout. There are many positives and negatives when using the relative layout. The main positive is that you can base where you want to put items from creating parents that they must follow.

Register Screen

The problem with this is that for example if you link texts to boxes as shown in this example it becomes very hard to line everything up and can take quite some time. Because it’s in relative layout you must make sure that all your buttons, text fields, and text are all linked up to the certain parent and are not getting in the way of everyone else. The CSS and JavaScript within this program are very similar to eclipse as it is an upgraded version of the program made for advanced programmers. The only difference I could find within the CSS is within defining the pixels of a certain object. The reason it is different is because instead of just calling 123px for a width you instead are going to go 123dp.

The DP in this program is a looks confusing but is actually quite simple. DP stands for “Density-independent pixels” which means they are flexible units that scale to uniform dimensions on any screen.

<EditText
android:id="@+id/password"
android:layout_width="213dp"
android:layout_height="43dp"
android:layout_alignStart="@+id/email"
android:layout_below="@+id/email"
android:layout_marginTop="12dp"
android:background="@android:color/background_light"
android:ems="10"
android:inputType="textPassword"
tools:layout_editor_absoluteX="187dp"
tools:layout_editor_absoluteY="205dp" />

As shown in code insert above rather than having pixels it is replaced with “DP” and based on this code you can see how it lays out on the registration screen above. When developing an Android application, use DP to display elements uniformly on screens with different densities. It really does not do much below you will see the code and basically it just formats it. Buttons also work the same way as in Eclipse you can use a on Click or even an event handler in order to perform an action against the button such as “Register” to add a new client.

Differences between Android and Eclipse

There are a couple differences between Android and Eclipse when looking at the two applications. Of course they both use Java so the main code is very similar but a couple differences such as the CSS with the pixels. Another cool difference is the code completion in Eclipse is more suited for a learning standpoint for students trying to learn Java, where as in Android Studio the IntelliJ software is built more for advanced programmers. What I mean by that is although there is a little bit of code completion given when writing your statements or java code it tries to make you write the code on your own so that you have a better understanding of the code and less help because if you are coding within Android Studio you should already have a good grasp of the main languages used.

Although they both have the same final product which is an APK Android studio has the edge in the idea that updates are constantly happening and the application is also backed by Google. Having used both Android Studio and Eclipse I found that although I am more experienced in Eclipse and have just started working in Android Studio the features within Android Studio far outweigh the basic features that Eclipse offers. It might be unstable with crashes still happening every so often and updates that tend to take a little too long the IDE overall is leaps and bounds ahead of Eclipse. Although it takes a little longer to get a hang of the program due to the file structure the advancements in the UI designer and the new features puts Android Studio over Eclipse any day.

Conclusion

In this blog post I have listed many different features, a quick recap of the last blog post I had, how to create a basic project, the main language used within this program, a deeper look at the interface of the GUI, and finally how it is more advanced compared to Eclipse. In my next and final blog post I will be talking about how Android Studio is compared to some Apple applications that have similar features and also my overall experience and recommendation of the product. Thank you for reading my second blog post and I am looking forward to hearing your opinions on my blog!

Jeff Sebastian

Software Development Student at SAIT Polytechnic

--

--