Android Development Tutorial 2

Android Development Tutorial 2In this tutorial, I decided to cover all of the topics I would need, so that in every tutorial that follows I can just make apps. Don’t try to memorize everything! Here I’m just covering a bunch of things you need to be familiar with.

We’ll cover the lifecycle of an Android activity completely. We’ll then look at how to make an app support many languages. We’ll look at how to grab string resources and how to pull them into java and xml files. Finally, we’ll look at the AndroidManifest.xml file in detail.

If you like videos like this, it helps to tell Google+ with a click here

Cheat Sheet From the Video

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- The manifest defines requirements, components and security for your app 
package: package name for the app
versionCode: Used to track app versions
versionName: App version displayed to users
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.newthinktank.helloworld"
    android:versionCode="1"
    android:versionName="1.0" >

    <!-- uses-sdk defines the minimum and maximum sdk version required on a 
    device to run your app. Always set min or it will default to 1 and probably crash.
    The targetSdkVersion should always be set to the latest version even if you 
    aren't using anything special from its api. It is best not to set a maximum sdk -->
    
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <!-- The uses-configuration defines hardware and software features your app 
    requires. Normally Not Needed because you should aim to have your app work 
    on any device.
    reqFiveWayNav: input device capable of navigating up, down, left, right
    reqHardKeyboard: hardware keyboard
    reqKeyboardType: required keyboard type
    reqNavigation: required navigation device type
    reqTouchScreen: required touchscreen type
    <uses-configuration
  android:reqFiveWayNav=["true" | "false"] 
  android:reqHardKeyboard=["true" | "false"]
  android:reqKeyboardType=["undefined" | "nokeys" | "qwerty" | "twelvekey"]
  android:reqNavigation=["undefined" | "nonav" | "dpad" | "trackball" | "wheel"]
  android:reqTouchScreen=["undefined" | "notouch" | "stylus" | "finger"] />
     -->
     
     <!-- You can define numerous hardware features your app requires
     using uses-feature tags like this. You are in essence requesting permission
     to use this hardware. Full list here: 
     http://developer.android.com/guide/topics/manifest/uses-feature-element.html
     
     If you want to note that it isn't required mark required
     as false. 
     
     <uses-feature android:name="android.hardware.bluetooth" android:required="false" />
      
      You can also set a minimum OpenGL version like this (Version 2.1)
      <uses-feature android:glEsVersion="0x00020001" />
      -->
      
      <!-- 
      A permission is used to restrict access to application components. 
      <permission android:description="string resource"
            android:icon="drawable resource"
            android:label="string resource"
            android:name="string"
            android:permissionGroup="string"
            android:protectionLevel=["normal" | "dangerous" | 
                                     "signature" | "signatureOrSystem"] />
                                     
       description: A description of the permission that can be provided if a user requests it
       icon: A icon that represents the permission
       label: The permissions name that is provided to a user
       name: When you want to refer to the permission in code use this name
       permissionGroup: The group of permissions that this one belongs with
       protectionLevel: The risk possibilities associated with giving permission
       - normal: Low risk permission that shouldn't hurt other applications, the system, or the user
       - dangerous: Higher risk permission that could provide access to private user info and could hurt the system
       - signature: A permission the system grants only if the requesting app has the same certificate as
                    the app that created the permission.
       - signatureOrSystem: Avoid this
       -->
      
      <!-- A uses-permission requests access to restricted code or data on a
      device. Each permission has a unique label. At install time the user
      will decide if it is ok to grant this power. If permission isn't granted
      the app may fail. Here is an example
      <uses-permission android:name="android.permission.READ_OWNER_DATA" />
       -->
    
    <!-- 
    supports-screens allows you to specify the screen sizes your app supports. Normally resizing
    applied by the system works for most apps and it doesn't require you to do anything if your
    app needs resized. You use this to define screen sizes that your app won't work with
    
    <supports-screens android:resizeable=["true"| "false"] // Is app resizeable
                  android:smallScreens=["true" | "false"]  // Does app work on screens smaller then HVGA
                  android:normalScreens=["true" | "false"] // Does app work on normal cell phone screens
                  android:largeScreens=["true" | "false"]  // Does app work on screens larger then cell phones
                  android:xlargeScreens=["true" | "false"] // Does app work on tablet screens and larger
                  android:anyDensity=["true" | "false"]    // Don't touch this (True by Default)
                  android:requiresSmallestWidthDp="integer" // Ignore this
                  android:compatibleWidthLimitDp="integer" // Upper bound your app may not work with
                  android:largestWidthLimitDp="integer"/>  // Upper bound your app definitely won't work with
                  
                  The last 2 either forces the user, or provide the user with the option to enable 
                  screen compatibility mode
     -->
    <!-- 
    There is only one application node. There are many attributes available here: 
    http://developer.android.com/guide/topics/manifest/application-element.html
    allowBackup: If false no backup or restore of the app will be performed
    icon: Reference to a drawable resource that represents the apps default icon
    label: The label that represents the app to the user
    theme: Reference to a style resource that represents the default theme
     -->
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        
        <!-- 
        activity declares any part of an apps interface and the main launch activity that you 
        want to run. 
        name: The class name that implements the activity
        label: Displayed on the screen if the activity is displayed
         -->
        
        <activity
            android:name="com.newthinktank.helloworld.MainActivity"
            android:label="@string/app_name" >
            
            <!--  
            Each activity has intent-filter tags. An intent is an operation that can be performed.
            Here we define the intents an activity can respond to. The intent-filter must contain
            one or more actions. Below MAIN and LAUNCHER tells  Android that this activity is the
            starting activity.
             -->
            
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    
    <!-- 
    service tags are used to implement background operations, or a communications API that
    is called by other applications. A service is any component that performs a long running 
    operation or supplies functionality to other apps.
    <service
  		android:name="MyService"
  		android:icon="@drawable/icon"
  		android:label="@string/service_name">
	</service> 
     -->
     
     <!-- 
     provider tags specify content providers used by the app. A content provider manages access
     to data repositories such as databases.
      -->

</manifest>

62 Responses to “Android Development Tutorial 2”

  1. Atif says:

    Hi , Derek I hope you are doing well .
    I’d like to say thank you soo much for these great tutorials , you are just covering everything im studying right now (preparing my master degree) .
    Let me tell you something , I learnt Design pattern(and many other stuff) from you , and my collegues were astonished when i showed and started to explain to them what i’ve learnt from you . Eventually some of them asked me where i picked this up , and of course the answer is new think tank (derek banas the genius) .
    I’d like to ask you to put the source code of the apps as a zip file . This way we can easily import it into eclipse . especially that it’s not going to be only just one class or two when you are working in android .
    besides that you are a genius . keep up the hard work .

    Hats off

    • Derek Banas says:

      Thank you very much for the wonderful compliment 🙂 I’m very happy that I have been able to help you. Yes, I will upload the whole package for every app I make from now on. Thank you for telling me that that would help. Everything will be 100% free to use in any way.

      Derek

  2. Michael Tirkey says:

    Hey Derek,

    Thanks a lot for these tutorials. This really helped a lot and cleared my doubts. Thanks again.

  3. ammar says:

    Thanks very much Derek
    that tutorial was very helpful for me

  4. Anirudh Menon says:

    Hello Derek!

    I am a beginner to Android development and a colleague of mine had suggested that I subscribe to your youtube channel. I found it very helpful. You have explained everything so well and have made it much easier to understand. Thanks a ton.

    I have also found many other useful tutorials like the Design patterns on your channel and will be going through them soon.

    I just wanted to thank you once again. You are doing a great job. Keep going. Here’s to a lot more wonderful tutorials from you. 🙂

  5. ram says:

    these are very helpful because I am doing an intern at a application company . Thank a lot.

  6. Hi,

    Greetings! Thanks for this wonderful tutorial. Can you please let me know what settings do I need to change to run my app in other languages?

    – Souvik

    • Derek Banas says:

      Hi Souvik, To change the language settings in Android :

      1. System Settings
      2. Look for Language & Input
      3. Click on the current language under Locale
      4. Select the new language

  7. babazumbula says:

    Way to go Derek, awesome video tuts! Keep up that way.
    Many, many thanks to you. Your work really helps me a lot!

    One more time I must tell you I really appreciate what you are doing.

  8. mussa says:

    thank u so match

  9. Your articulation of app development is impressive. I’m on board…

    Regards,
    ECMcCready

    • Derek Banas says:

      Thank you 🙂 I’m experimenting with a new way to teach app development which is based around actually making apps. It will be a long process, but I think in the end that anyone that watches all the videos will actually be able to make most anything.

  10. TestName says:

    It would be nice if you could (after you complete the whole android tutorial) programm an android app from scratch, i think it would be very helpful to see all the topics combined with each other

    • Derek Banas says:

      I definitely plan on doing that. As I have been teaching Android I also have learned a great deal about concepts that people get confused about. I may do a reboot on the Android tutorial and as you said make a complete app that has as many features as possible.

  11. Raul says:

    Derek, did you upload the cheat sheet? I just see a static text, not a hyperlink (using Chrome on a mac).

  12. Gajanand Verma says:

    Thanks for your tuts, very useful n very innovative thanks once again.

  13. Ishiaku says:

    what I can say that has not been said already. You are a genuis Mr. Derek Banas. A gift to the programmer’s world.

    Most grateful I everly remain. Bravo!

    Ishiaku

  14. Taylor says:

    Hey Derek Banas,

    I have just completed watching your first Android Development Tutorial and i don’t understand the reason behind why you have to go back and forth between the different files to connect the EditText and stuff. Would you recommend me watching other tutorials or are there websites which may help me with the fundamentals? Or must i simply just watch the tutorial again until i understand what is occurring.

    Cheers

    • Derek Banas says:

      I do that to try and keep everything interesting. I’m sorry if that was distracting. Rewatching may help, but I’m not so arrogant as to say that there aren’t better Android tutorials out there. Many people are making them. I wish you the best 🙂

  15. alfonso says:

    Hey Derek! I have a question about minSdkVersion. It is currently set to 19, which is the same value as in my targetSdkVersion, should I lower the minSdkVersion in order to make the app backward compatible?

    Thanks!

  16. Anonymous says:

    thank you,
    but can you help me with my app??
    im making an android app.. just like movie quiz game ..
    can you teach me? plz??

    THANK YOU VERY MUCH.. 😛

  17. Rajat Jain says:

    whenever i try to input from keyboard the app force closes.
    Can you please tell me what i am doing wrong here.
    Thank You

  18. Markus says:

    what kind of programs
    do u use ?

  19. Andrew C. Contino says:

    Hey Derek,

    I have one concern I would like to mention to you. I have been following the tutorials using NetBeans IDE and my android manifest.xml file is not exactly the same as yours. I only have one my Main_Activity but my display_message_activity is not there? Do I need to edit my manifest.xml manually because I’m using netbeans? Just a little stuck. Great tutorials too by the way! Very helpful!

  20. Jayson says:

    You’re tutorials were the most amazing and helpful tutorials I had ever watch. I have a capstone project and I decided to create an android app but I can’t decide what app should I make because I don’t know if I could do it or not. I need this project to graduate please help 🙁

    • Derek Banas says:

      I’ll be starting a new Android tutorial very soon. I’ll approach Android from a different angle. This tutorial teaches with a focus on making apps. Next time I’ll mix it up a bit with many more diagrams on what is happening.

  21. Tamir Schwarz says:

    Hello Derek,
    First of all, thank you very much for those tutorials; they are really helpful and understandable!
    I have a question about the Spanish strings.
    Let’s say I want that app name will be in Spanish,”Primera App”, do I need to change the file in “res/values/string.xml” to be in Spanish or can I make a reference to values-es?

    (something like “R.id.edit_message” )

    • Derek Banas says:

      Hello Tamir, The way Android handles translation is if the users device is set to Spanish then it will use the text in the values-es folder. It won’t however allow you as the app designer change the language. If you want to offer translation at anytime then you’ll have to use Googles translation API

  22. Rowan says:

    Can i copy the ‘cheat sheet’ to notepad++?
    How? I now the normal way (ctr+c) but than i see all the numbers dubble.

  23. aniket says:

    Thanks a lot Mr.banas !!!
    Awesome tutorial , so clear and easy to follow…
    i have a question .i using android studio for practising. when i click on run it gives this error “emulator: ERROR: x86 emulation currently requires hardware acceleration!
    Please ensure Intel HAXM is properly installed and usable.
    CPU acceleration status: HAX kernel module is not installed!
    ” .can you help plz….

Leave a Reply

Your email address will not be published.

Google+