technology

Diving Into Your First Android App

Android apps are, for the most part, written in Java, but at first glance the code can be unrecognizable. From philosophical sounding Android-specific classes (like Context and Intent) to lengthy XML files, the process of creating an Android app may seem unintuitive and tedious. It has been just about a month that I’ve been able to get my hands dirty in Android development (mostly UI) and I have gathered some helpful tips for those that are familiar with Java, but not so much with app development.

android-5-lollipop-development

Photo courtesy of diygenius.com

Android Studio, the official IDE of Android, has a GUI that allows you to create Activities (the views that comprise an app) without having to write much code. You can simply select “Create New Activity” and click and drag the elements you want onto the screen, such as a text box, or a button. While this is useful for someone who has no idea what they are doing, some of the automated code that is produced by the GUI can be more confusing than helpful. It adds default themes and transitions and other properties that can really mess you up if you don’t know where to look to change it. The GUI can be quite puzzling because creating/customizing an Activity can alter code in three separate files.

To create an Activity, you (or the GUI) need to create 1) a class for the Activity, which is where you can put the logic and functionality for the Activity, 2) an XML file, which will specify the UI elements and determines much of the appearance of the Activity, and 3) declare the Activity in the Android Manifest, which is like the blueprint of an Android app.

It is easy for the GUI to become a black box, that creates an app without you really understanding what is going on. If you are creating a very simple Activity, with only one element, say an EditText for the user to enter their phone number, the GUI may actually be the quickest way to make it. However, if your Activity contains a couple of images, and multiple TextViews, for example, I recommend avoiding the GUI and just writing the XML code yourself. The GUI can be very uncooperative when there are more than two or three elements that you are trying to position within the Activity.

I had to discover this the hard way, so I’ll spare you: when trying to format an Activity with many elements, use a layout. Two of the more common layouts are 1) Linear Layouts, which organize elements into rows or columns, and 2) Relative Layouts, which specify element locations relative to other elements in the layout. Some of the most helpful resources that I found while formatting Activities are here for Linear Layouts and here for Relative Layouts.

I hope this helps as you start building your first app! Stay tuned for upcoming posts to hear more about my Android journey. More tips to come!

Discussion

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s