Android Development Tutorial

Android Development TutorialIn 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+ [googleplusone]

Code From the Video

activity_main.xml

strings.xml

MainActivity.java

DisplayMessageActivity.java

156 thoughts on “Android Development Tutorial”

    1. I’m uploading it today. I’ll cover a bunch of technical things so I can get them out of the way and then just make apps in every other tutorial that follows.

  1. 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

    Regards

    Waqas Asghar

  2. 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.

    1. Thank you very much for the nice message 🙂 I do my best to improve on each tutorial series. I’m very happy more people have been watching them

  3. i am geting this as error
    “editmessage cannot be resolved or is not a field”
    what to do .plz help???

      1. 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.

        plz help me in solving that.

  4. Hi Derek, brilliant instructions although I still don’t get parts of it and when I try and apply my own coding I struggle with debugging and knowing what to do.

    I’d really like to program for Android devices as I’ve a few ideas knocking around but would you recommend me learning Java first?

  5. 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

    1. 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!

  6. hello,

    Again can you tell me why there is NOTHING listed in Hierarchial Parent: “””com.newthinktank.firstapp.MainActivity”””

    I decided to my application as you did and under Hierarchial Parent there are NO choices. thks

  7. 10X Derek
    now I finish my exam for this simister.
    now i have some problem, i get an error

    [2013-07-08 12:46:14 – FirstApp] ——————————
    [2013-07-08 12:46:14 – FirstApp] Android Launch!
    [2013-07-08 12:46:14 – FirstApp] adb is running normally.
    [2013-07-08 12:46:14 – FirstApp] Performing com.example.firstapp.MainActivity activity launch
    [2013-07-08 12:46:14 – FirstApp] Automatic Target Mode: Preferred AVD ‘sasd’ is not available. Launching new emulator.
    [2013-07-08 12:46:14 – FirstApp] Launching a new emulator with Virtual Device ‘sasd’
    [2013-07-08 12:46:16 – Emulator] Failed to allocate memory: 8
    [2013-07-08 12:46:16 – Emulator]
    [2013-07-08 12:46:16 – Emulator] This application has requested the Runtime to terminate it in an unusual way.
    [2013-07-08 12:46:16 – Emulator] Please contact the application’s support team for more information.

  8. Hi Derek,

    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.

    Regards,

    Stony Creek Consulting, LLC
    Joseph J. Geller

    1. 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
      Derek

      1. If you are planning to make tools that will allow people to quiz themselves, I would love to help you.

        I am currently viewing your design patterns and android tutorial and they are so easy to understand.

        Thank you, Derek 🙂

        Searock

        1. 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 🙂

  9. Emulator doesn’t load when i press the play button thought it does load when you do it throught the setting method

  10. DO you have videos which shows have to add buttons and text boxes have to changes colours and ETC

  11. Hey, man!

    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.

    Greetings from Bulgaria!

    1. 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.

      Best of luck

  12. great job sir !!!!!1
    tell me….list of the java concepts,..one should know…to basically understand these android tutorials…..
    thnkiewwww veryyy much 🙂 🙂

  13. Hello Sir,

    Im getting a redline under the edit_message..
    Im not able to resolve it at all…..
    I tried your code too….
    Is there any way you could help me? I cannot proceed at all if i dont get this. 🙁 🙁

      1. I have the same problem. It appears that edit_message cannot be resolved or is not a field.

        What Can I do?

          1. My code is the exact same as yours, copy pasted to make sure, but edit_message seems to not be resolved. Maybe my generated R file is different from yours?

            1. I have the package file available for download. If you are having trouble with the r file part 26 of my android tutorial shows how to update to the newest version of eclipse.

              1. Thanks. I ended up just following the official android tutorial and it somehow fixed the problem. I appreciate your quick reply!

  14. Please ignore, my last comment; it turns out that the error was caused by putting the activity_main.xml in the DisplayMessageActivity.xml these tutorials have been amazingly helpful and simple.

  15. 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.

    I hope this site and your videos is always available.

  16. Absolutely great!!!
    voice is clear and understand your every code very clearly…
    Thanks for your tutorials i am gonnna build my first app soon.. 🙂

  17. Hi Derek,

    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 !

    Thanks

      1. Hi Derek,

        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

        ActivityForThought
        Enter a Message
        Send
        Settings
        My message
        Hello world!

        the last tag is “Hello World!” , this is what i get as an output !!

        activity_main.xml:

        DisplayMessageActivity.java:

        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent= getIntent();
        String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
        System.out.println(“message is:” +message);
        TextView textView = new TextView(this);
        textView.setTextSize(40);

        textView.setText(message);
        setContentView(textView);

        setContentView(R.layout.activity_display_message);
        // Show the Up button in the action bar.
        setupActionBar();
        }

        activity_display_message.xml:

        In the MainActivity.java i have following function:

        public void sendMessage(View view){
        Intent intent = new Intent(this, DisplayMessageActivity.class);

        EditText editText = (EditText) findViewById(R.id.edit_message1);

        String message= editText.getText().toString();

        intent.putExtra(EXTRA_MESSAGE, message);

        startActivity(intent);

        }
        Meanwhile, I will try on my own and see why this is happening !

        1. OK , I see that xml tags are totally messed up which i tried to paste in above comment !! Please ignore them if they confuse you. I will try to resolve this error !

          thanks

          1. Hi Derek,

            I was able to resolve it ! My bad that I missed a line in code , which i was supposed to comment out in display_message_activity.java

            setContentView(textView);

            //setContentView(R.layout.activity_display_message);

            after i commented above mentioned line, it started working just fine 🙂 ..

            Thanks a lot for your time and help on this !! I really enjoy watching your tutorials 🙂

            Thanks
            Kuldeep

  18. Hi Derek

    Thanks for your tutorial.

    I didnot get the reason you give View as input to the sendMessage method?
    What exactly view is here and how does it differ from context..

      1. So, the View object passed to the sendMessage() function is that of the button?

        Btw, thanks a ton for the awesome tutorials!

        1. 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.

  19. 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

    1. This is a common error. There are a few ways to get rid of it.

      1. Make sure you delete any imports that look like the following in all the class files in your source directory : import android.R

      2. Make sure the file names in your layout folder are all lowercase

      3. Try deleting R.java in your gen folder

      After doing the above click Project -> Clean

      1. 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

        1. Hi Victor, Project -> Clean should generate it.

          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.

          1. 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???

  20. how do i turn on the assist in eclipse you know that box that helps you with the library to show you what should or could be in the place that you are typing

    1. Go to preferences, Java -> Editor -> Content Assist and edit the “Auto activation triggers for Java” field

      Type .abcdefghijklmnopqrstuvwxyz in “Auto activation triggers for Java” field

  21. Because of your fine videos, I registered a developer account at the Samsung web site and started to pick up Samsung’s unique features.

    Many thanks for publishing and sharing your expertise. Please put my name in the hat for the Galaxy Note 3/Gears drawing.

    Have a great weekend.

  22. it is a great tutorial. thank you very much. but there is a little problem.
    Hierarchial Parent: com.newthinktank.firstapp.MainActivity
    I could not find this option, would you show me why?

    1. 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.

  23. 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..

    1. 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.

      I hope that helps
      Derek

  24. 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

  25. 1st Off.. Awesome job!!! Keep spreading the good word!!!

    I am using ubuntu 13.04 and out of the box I had a problem of resolving:

    import android.support.v4.app.NavUtils;

    but.. the was easily corrected adding a the jar file to the build library.

    Project -> Properties -> Java Build Path -> Libraries (tab) -> Add Jar..

    The .jar file is the one found at:

    [path-to-andorid-sdk]/extras/android/support/v4

    Just thought I would share..

    Again.. keep up the good work!!!!

    kindly Ray

  26. Hi, I had to erase the

    AndroidManifest.xml is updated with the following by eclipse…

    In order to make it work, why?

    Thanks

  27. 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?

    Thanks!

  28. Hi Derek,

    Can you explain why we use “com.example….”?

    public final static String EXTRA_MESSAGE = “com.example.myfirstapp.MESSAGE”;

    Thanks for everything

  29. 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?

  30. Hi Derek,

    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”.

    Please tell how can I fix it?

    Thank you

  31. Hi, I got an error saying ” Attribute is missing the Android namespace prefix”, on all the lines , im not sure where i went wrong. Please help if you can.

  32. Nice tut bro. Dude i wanna know how to make my stock rom(xolo q600) status bar to looks like samsung galaxy s4 status bar? pls say me step by step. i have little knowledge in android apk decompile and compiling. Looking for your reply.

  33. 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.

    P.S.: I truly love your videos, I think you’re awesome :D

    1. 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” 😀

        1. 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 😛

          1. Thank you 🙂 Feel free to ask questions. I do my best to answer them all. I was very sick this weekend, which is why it took me a while to get back to you.

  34. 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?

    Thank you.

  35. 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:”

    Can you help me solf this problem please?

  36. 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

    starting here:

    AndroidManifest.xml is updated with the following by eclipse

  37. Mine does not display the message. I think it could be a problem with the Fragment display message.xml.

    1. 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.

  38. Derek,

    could you please me how to debug an issue an app says “unfortunately the UI/App has stopped” (in either a real device or a simulator)? is there a tutorial that talks about it?

    I am using ADT v22.0.0-675183. Thanks.

    Thanks,
    -Yao

      1. Hi, Derek,

        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.

        thanks,
        -Yao

  39. Hello. In my Manifest.xml, there is an error “The markup in the document preceding the root element must be well-formed.”

    What does this mean?
    On Eclipse, the error appears on line one
    <<<<<<< Original

  40. Hi Derek,
    I just wanted to thank you very much!!! I am so happy that there are people like you!!! God Bless You!!! Live long and happy life!!! Everybody should learn from your deeds =)

  41. 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

      1. There are no red dots there, I corrected all of them and they all disappeared before I ran the program, I can’t see any signs of an error, but the problem persists.

  42. Thank you for the great tutorials Derek. Please would you tell me how to generate numbered source code like yours on eclipse?

Leave a Reply

Your email address will not be published. Required fields are marked *