Donnerstag, 6. November 2014

[Android Tutorial] 3. Setting up your system

I don't know if you skipped the last part and started right here so i'd like to welcome you to my tutorial about android development. Let's welcome back Mike, our little developer who wants to develop an android application.
Let's get stuff going!

Downloading Eclipse

Use this link to the official google android developing page. Click "Download Eclipse ADT" and follow the downloading procedure.
Extract the downloaded zip folder and navigate to the "eclipse" folder.
Run "eclipse.exe".

Some basics about android projects

Before Mike starts developing he needs to know some stuff about the project structure. He starts by reading this book. Fortunately Mike speaks german fluently. If you don't you can read the head first book about android development. I haven't read it but most of the head first books are great for beginners.

Structure of android projects


The sourcecode of android applications is located in the src folder like in every other java project.
Images are svaed in the res/drawable folder. Activites and fragments are located in the res/layout folder. Android is generating files inside the gen folder. NEVER TOUCH FILES IN THE gen FOLDER.

Activities and fragments


An activity describes one user interface. The official styleguide of google states that one activity should only be there for one specific task. E.g. one for logging in, one showing the main menu and another one showing some data.
A fragment is a reusable component which can be used in activites.

AndroidManifest.xml


The AndroidManifest.xml describes the android application. It contains most of the components like activities, the used android version,  and so forth. If you need to get access to system components like the file storage or the camera you need to mention that in the AndroidManifest.xml.

Now that Mike got an idea how android projects are structured he starts by creating an android project in Eclipse.


Creating your first project

Mike didn't use Eclipse yet so he's asking the his asian coworker Co Ding how to create a new android project:

[Mike] Hey Mr. Ding, i got a question about creating a new android project in Eclipse.

[Co Ding] Greetings Mr. Mike, the answer is pretty simple. Just navigate to "File - New Project - Project..." now a popup opens where you can select what kind of project you want to create. You need to select "Android - Android Application Project". Now you can set some options for your new project.

[Mike] Woaaah, that's really simple. But i have no idea which options i should choose.

[Co Ding] Of course it is. Well, let me set something straight first: NEVER LET ECLIPSE GENERATE AN ACTIVITY FOR YOU.

[Mike] But why shouldn't i let Eclipse generate an activity for me?

[Co Ding]  If you want to know this you can look at this post which explains the problem and shows  how to solve it.

[Mike] Alright, Mr. Ding. But how should i create an activity instead?

[Co Ding]  Have a look at this todo list:
  1. Navigate to the "res/layout" folder
  2. Create a "New Android XML File
  3. Navigate to your "src" folder
  4. Create a new class extending android.app.Activity
  5. Open your "AndroidManifest.xml"
  6. Add the following lines (The part in the brackets is only needed if the activity is you lancher activity!)

        
            [
           
                

                
            
             ]
        


[Mike] I guess i got it. I'll have a look at it by myself now. Thanks for your help, Mr. Ding.

[Co Ding] No problem, Mike. If you are having troubles or you didn't understand a thing you can ask me by writing an email to loris.bachert@gmail.com.

What are we going to do next?

In the next tutorial we will face the UI design and we start writing a HelloWorld. I hope you liked it :)