In a previous tutorial, I showed you how to Install the Android Development Tools. In this first part of my Android Development Tutorial I’m going to describe almost every file and folder used to develop an Android app.

I’ll walk through every single file and explain how it is used. I’ll explain the whole file system. We’ll also make an app and as I create it, I’ll explain every single step and what everything means. I have never seen anyone try to teach this much in one video. I hope you enjoy it. All of the commented code is available below.

If you enjoy videos like this, it helps to tell Google+

Code From the Video

activity_main.xml

<!--
We are going to use the LinearLayout this time. It Aligns all elements
in one direction. We will define that by setting orientation to
horizontal. LinearLayout is the root view and it will fill the
devices screen.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<!--
To create a editable text field add an EditText element. By setting
id you'll be able to reference this element in your app code. @ is used
when referring to an object from XML. Then id is the resource type. Then
you have the resource name. You use the plus sign only when you create a
resource for the first time. We use wrap_content to avoid using pixels.
hint is the String that will be displayed in the textfield by default.
This refers to a String resource that is defined in another file.
If you want the textfield to fill the space not taken up by the button
you can assign layout_weight with a value greater then 0. Every element
has a default weight of zero. If you give one element a weight of 2
and the other a weight of 1, the first will take up 2/3rds of the row
and the next the last 3rd. layout_width is now irrelevant because the
weight has been set.
-->
<EditText android:id="@+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />
<!--
Use Button to create a button. Pull the String for the button from
strings.xml
By assigning sendMessage to onClick, when the button is clicked the
method sendMessage will be executed.
-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage" />
</LinearLayout>

strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">First App</string>
<string name="edit_message">Enter a Message</string>
<string name="button_send">Send</string>
<string name="action_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
<!-- Message String put here by Eclipse when DisplayMessageActivity
was created -->
<string name="title_activity_display_message">My Message</string>
<string name="hello_world">Hello world!</string>
</resources>
<!--
Text used in a user interface should be saved as a String
resource, so that everything can be managed in one place.
-->

MainActivity.java

package com.newthinktank.firstapp;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends Activity {
// Store a unique message using your package name to avoid conflicts
// with other apps. This stores the message I plan on displaying
public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
// This method is called when the user clicks on the Send button
public void sendMessage(View view){
// An intent is an object that can be used to start another activity
// this is a reference to MainActivity
// MainActivity is of type Activity, which is of type Context.
// A Context can represent various application specific
// resources. Different resources gain access to others because
// of shared methods inherited from the Context class.
// DisplayMessageActivity is an Activity we want to start
Intent intent = new Intent(this, DisplayMessageActivity.class);
// Create a text area and place it in the view
EditText editText = (EditText) findViewById(R.id.edit_message);
// Store the text in the text area
String message = editText.getText().toString();
// Add the text to the intent
intent.putExtra(EXTRA_MESSAGE, message);
// startActivity causes the Activity to start
startActivity(intent);
}
}

Hey derek … how r u man?? Thanks a lot for starting android series. I was waiting for this for a long time. now finally world best teacher will teach us how to make apps in android. May God bless you. Stay Happy and blessed

Great starting point forAndrois development ! I like your teaching methodology Derek. It’s clear, concise, up to the point and funny 🙂
You are really a special person !
I like also very much your tutorials on OOP and design patterns.
Wish you a successful continuation.

yes.now when i rewrite code again in eclipse its giving—-
W/ResourceType( 4400): Bad XML block: header size 92 or total size 0 is larger than data size 0
W/ResourceType( 4400): Bad XML block: no root element node found
C:\Users\kk\workspace\Myfirstapp\res\layout\activity_main.xml:30: error: Error: No resource found that matches the given name (at ‘hint’ with value ‘@string/editmessage’).
C:\Users\kk\workspace\Myfirstapp\res\menu\activity_display_message.xml:2: error: Error: No resource found that matches the given name (at ‘title’ with value ‘@string/menu_settings’).
C:\Users\kk\workspace\Myfirstapp\res\menu\activity_main.xml:50: error: Error parsing XML: junk after document element.

Thank you very much 🙂 Yes you need to understand the basics of java. Here is my Java Video Tutorial. All you need to watch are parts 1 through 17. Feel free to skip parts 8 and 10 as well. Feel free to ask questions

Derek, you too much, can l ask whether you have study educational psychology before, because it gives you a good command in delivery a lesson, l think you love this job, keep it up, hope to learn from you and keep in touch with you.
Folks, he did a great job. Thumps

Thank you 🙂 I have taught many people in the past. First when I was a software architect, it was my job to teach new hires in a away that is very similar to what I do online. I also used to teach job skills to unemployed people for free. Yes, I love to teach, but for now I only teach online. I’m very happy that you enjoy the videos!

I have taught classes in IT myself and also listened to a boatload of instructional videos over the years and your tutorials are the crème de la crème. Clear voice with just the right volume. I am also amazed at how you do it without halting plus keeping synchronized with the excellent video I can follow along with in Android Studio.

The “just do it” method is the way to learn with your excellent commentary in the background, explaining the ins and outs as the tutorial progresses.

I can’t say enough about how these are helping me with getting into mobile development. Keep up the excellent work. These make learning a difficult subject a pleasurable and rewarding experience.

Thank you very much for the kind words Mr. Geller 🙂 I greatly appreciate them!

I just started making videos with an open mind and took the advice that my viewers gave me. If they weren’t nice enough to tell me how I could improve I would have never made it to the point in which I now make pretty good videos.

I still have a long way to go. For example I know I need to provide tools that will allow people to quiz themselves and I plan on making free apps very soon to do that as well. I hope to some day cover math and science in the same way.

Thank you very much for the offer. Yes I’m planning on creating free Android apps that will work together with the video tutorials. I may reach out to people in the future. It will be a big undertaking on my part. I’m very happy that you enjoyed the videos 🙂

Great job on all of the tutorials you did. Mainly, I am doing Web Application Development, but recently started doing some Android applications. I randomly saw your Android videos and decided to see in what way and how you explain things. You’re just awesome! Keep up the good work. I should start doing tutorials, too, so I can help people in need.

Thank you 🙂 I basically just took the advice I received on YouTube. That is why I’m different from most other tutorial guys. I also don’t watch other tutorials to keep from being influenced.

You definitely should give the tutorial thing a go. I dream of a day in which a free education will be available for everyone in the world. I definitely can’t cover everything on my own. Always feel free to ask for advice. There are many things I wish I would have known in the beginning.

Derek, I have seen so many tutorials on the web, they all have great technical info.
But your tutorials not only have great content and technical info, the way you communicate, everything becomes so easy to learn and understand.

Firstly thanks a lot for such nice tutorials ! I was able to proceed further and did try this first tutorial on eclipse. However, I get strange output when i click on the button SEND. Whatever message i type in text box prior to pressing SEND, the next screen prints “hello world” .. I am not sure why it happens !! I am trying to debug it, but in case someone already asked you this before, it would be great if you can please let me know what mistake i might be doing !

There is no error, but the output is not correct. I mean lets say i type a message on the text box ” I am kuldeep” and then click on SEND button. The next screen shall show “I am Kuldeep”, However, it shows “hello world” !! So the functionality is not working correctly. If you see that in strings.xml

You’re very welcome 🙂 A View is the base class for all components in Android. It is generic like Object is a base class of every other Object. The View being referenced here is the Button that was clicked.

I copy and paste the entire tutorial, and I am getting an error message, after 4 hours of reinstalling eclipse 3 times, I just don’t know what the problem is. When I try to run the application I get an error messages telling me that ” R can not be resolved to a variable ” setContentView(R.layout.activity_main); It highlights in red the letter “R” can you tell me how to fix this please. the same message appears 3 times in my MainActivity.java file.. also appears in inflate(R.menu.main, menu); pls helppppppppp

Thanks For help. I follow the steps but I realized I don’t have a R.java in my gen folder. So the ” R canot be resolved ” message still appaears. Is there anyway to manualy bring that file. Since I have done this project 3 times and install eclipse 3 times, I feel I can not move to your next lesson.. Should I try Andriod Studio or Netbeans? or s ther any specific version od Eclipse that you recommend I have the Kepler version with all the updates.. please advise
Thanks
Victor

Did you install the new Android Development Tools yet? It is very stable, but it sometimes requires you to downgrade to Java 1.6. I will upload a tutorial on how to install it either tonight, or tomorrow.

Don’t use Android Studio, or NetBeans in my opinion because they are terribly buggy.

Thank you so much Derek, I use a different version of eclipse, and finally was able to finish this tutorial, I am exited to move on to the next. However, after I was able to run the program without getting the error message:” R cant be resolved”, The gen/R.java disappear from my folder and that error message came back resulting in me not being able to run the app. I feel maybe is my pc deleting the files.. But At least I know the code works but I can’t run it again due to this error message. is there any way I can make the file R.java come back to the gen/folder? or do I have to build the project form scratch again???

Thank you 🙂 When you are creating a new Android project you define the custom name. I use newthinktank because that is my website. It should be a unique name. You should define your own. The default is example.

Hey your tutorials are really awesome and up to the point..
I am going in final year of Computer Engineering and planning to develop an android app in the final year, a wanted some suggestions for that..
Few suggestions would be helpful..

Thank you 🙂 There are so many different apps that you could make. What I’d do is look at what are the most popular apps on iOS that aren’t available on Android and make them. You’ll have to change them so you avoid copyright issues, but that is definitely a direction to go. I always learned best by trying to copy something that was already great. It gives you a clear final goal to aim for.

Thx very nice tutorials. I saw some of them.
I think youd should mention at the beginning of the tutorial that this tutorial is not suited for Android Beginners, because you mostly go fast with the explanations and sometiome you don’t explain the code what’s happening. So if you are completely new to Android they can’t follow the tutorial, or the can follow by just typing your code but don’t really unterstand how it all work

Very useful tutorial! I have one problem though. I followed all the steps here and I don’t have any errors also. My emulator is running with the app. I can enter any text in the textbox and I am being directed to the display_message page. But the message is not being displayed. I am just getting a blank page. Did I miss anything?

Hi, I love your tutorials. Really helpful.
I was planning to start the android development tutorial while doing the java tutorial.
When do you think I should start the android tutorial or should i complete all java tutorials?

Thank you 🙂 You don’t need all the Java tutorials. If you watch 1 – 18 ( Minus 8 and 10 ) you’ll learn most everything you need. You may also prefer to better understand OOP by watching the first 2 videos in my design patterns video tutorial. Since everything in Android is based on MVC you may also benefit from watching my MVC video tutorial. I hope they help 🙂

Thank you for the great tutorials. I have a problem with emulator. Whenever I try to run the MyFirstApp, in emulator it says “Process system isn’t responding” and in the Console it says”unable to install on the device”.

When I create the new Activity, Android Studio tells me to sync the gradle files. When I do that, I get loads of errors in the DisplayMessageActivity.java file, it can’t find the R.java file and so on. Is this purely because of Android Studio? How can I mend this? Because I really want to use this instead of Eclipse. I’m using Android Studio 0.4.6 (19 February) on Ubuntu 13.10.

I’ve created a new project and carefully selected the right R file (from com.me.app, not from android.r) from the dropdown list (android studio auto imports everything) and now everything seems to be working. Sorry for bothering you for that!

As I said before, you’re doing a truly awesome job and I can’t wait to get my first paycheck so I can “buy you a beer” 😀

I know there’s no need to, I just want to 😀 I’ll probably be bombing you with questions in the upcoming weeks when I get into more advanced stuff (I’m just at tutorial 5 now), so I apologize in advance :)) and that’s not because you’re not a good teacher, but because I’m a very curious person 😛

Hey Derek!
Thank you for your awesome list of tutorials. I really appreciate what you do and like you style of teaching.
I had one question in my mind – is it possible directly drag the textfield component into the activity form, edit its content and run emulator to test it? Or should I do all the revisions and string modifications in string.xml?

Hi Derek, Thanks for the amazing videos!
i just started to learn, and i did eveything you said, but i get an error saying ” activity cannot be resolved to a type ” in the DisplayMessageActivity.java in the line where the code says ” case android.R.id.home:”

I tried the writing myself but eclipse has changed since you made this tutorial (fragment added and who knows what else)
so it had many errors.
now I tried copying and pasting everything from here, and the lower part of DisplayMessageActivity from line 82 is filled with errors

I finally got it going by using your tutorial. For some reason it didn’t work using the android developer website. I thought it might not work because there were some differences in the code but figured it out.

I don’t remember there was any useful message in the bottom panel in eclipse.

unfortunately I have deleted the project. it was when I follow this tutorial of button send, with your fix for the fragment.xml problem, things seems a little weird, but it might also be some error caused by me.

I was wondering whether there’s any possibility for in-circurt debugging so that when it crashes, we could get an core dump or call stack or something, but I didn’t find any. maybe it is not possible.

I am now try to follow the android website tutorial and do this all over again.

Hi Derek, I built an android program from scratch with the aid of your second tutorial, but this program won’t run, my IDE couldn’t detect any errors in my code, yet I get an X sign on the project but not on any other files in the project, my Main.java is OK, so is Main.xml and string.xml, but this program just won’t work, it keeps telling me whenever I try to run it, your project contains error(s), pls fix them before running application, this is so annoying, pls help. Thanks