Skip to content

Latest commit

 

History

History
471 lines (341 loc) · 21.9 KB

File metadata and controls

471 lines (341 loc) · 21.9 KB
layout springboard
title Intro To Android Programming

Intro To Android Programming

Intro

What is Android?

Android is a Linux Kernel based operating system developed by Google. It originally started as a mobile OS, but has now expanded to:

Android TV

![Android TV](img/androidtv.jpg)

Android Wear

![Android TV](img/androidwear.jpg)

Android Auto

![Android TV](img/androidauto.jpg)

Why Android?

  • Thousands of Unique devices supported
  • Written in Java
  • Amazing IDE
  • Play store is more lax.
  • Well documented

Getting Started

Development in android is done in Android Studio, a Google developed IDE that makes working on Android simple and fun! You should go ahead and snag the IDE online, or ask your local organizer for a preloaded thumb drive.

Resources

Basic Structure of an App

![Activity Structure](img/activitylayout.png){:class='short'}

What do these words mean?

  • Activity
    • Activities are the basic building blocks of your
    • Each screen in your app would be an activity
  • Actionbar/Toolbar
    • The toolbar at the top is known as the ActionBar (Renamed to Toolbar in Lollipop)
    • It is optional, but useful
    • Usually contains frequently needed actions and options menu and title
  • Fragment
    • Fragments are subsets of activities
    • Multiple fragments in one activity
    • Can be moved around to create Tabbed Layouts or NavDrawer Layouts

Lets start the tutorial

So, today we’ll be making an app called clickzilla which introduces you to making a basic activity, layout and using intents and also using the options menu. Here’s the completed code for this project for reference https://github.com/adibalwani03/ClickZilla

Create a New Project

  • Lets create a new Project
  • On the next screen you'll be prompted for the following
    • Name
    • Package Name You can name these anything you want. I called the app ClickZilla and and the general convention for package name is com.<yourhandle>.<appname>
![New Project](img/startproject.PNG)

Name your application

On this screen you will enter your application name and your company domain. If you dont have a website then you can pick any domain but it should be unique because 2 applications with the same package name cannot exist.

![Application Name](img/applicationname.png)

Support

You can support as many systems as you want. I tend to prefer supporting anything Android 4.0 or above.

Android 2.3 is now dead, so no need to support that and Android 3.0 is just plain weird so I like to pretend that never happened.

You can also add support for Google glass, TV, Auto and Wear if you want. Android Support

Activity Templates

And now you’ll be taken to the templates screen which contain prebuild activities you can use. For this one, we will be sticking to a basic activity but you can also pick blank activity which is just a basic activity without some of the boilerplate code. The other templates are for more specific situations but if any of them fit your app then you can choose that.

![Choose Activity Type](img/chooseactivity.png)

Activity Name

Now we give the activity a name. Again, usual convention is that the first activity the app is called MainActivity Or, if the app requires login then you can start at loginActivity or a DispatchActivity (which checks for already logged in users) But these are just conventions so you don’t have to strictly follow them

![Name Activity](img/nameactivity.png)

And now we wait

For a million years for gradle to get ready

![Building](img/building.png)

Meanwhile...

What is gradle?

Gradle is the build system that Android Studio uses to build all apps. It is essentially a build automation system. In your build.gradle file you can declare dependencies, signing configurations for APK signatures, flavors of the app (Such as specific builds for different versions of Android, or debug and release flavors) Most of the time you will not need to make changes to build.gradle since Android Studio automates most of it (Automation for an Automation system, Yo Dawg!), but it is useful tool know to make certain things faster. For example, if you define a signing config for your release version in gradle, all you need to do is run “$gradlew.bat assembleRelease” and it will generate a complete signed APK.

Congratulations!!

You have completed your HelloWorld app.

Over the next few slides I’ll go over the automatically generated code and then we’ll start making changes

![Hello World](img/helloworld.png) {:class='wide'}

File Structure

Here you can see the basic file structure of your app. Each folder here has a specific purpose which the following slides will explain.

![File Structure](img/filestructure.png)

Manifests

The Manifests directory is where you declare your AndroidManifest.xml and any other manifests.

![Manifests](img/manifests.png)

The purpose of the manifest is to specify things for the device including declarations of all activities, all permissions required (eg. Internet, Wifi, I/O), special hardware requirements (camera, flash, gyro etc) and certain google APIs (eg. maps) and other things that can possibly affect compatibility.

NOTE : Some of the tasks a manifest does is now also being done by the build.gradle such as declaring minimum android version

Java Packages

The java folder is where all your packages are declared, and inside those are all your java files. Most of your code would go in the main package.

I personally have never used the AndroidTest package, so I can’t say much on that, but i’m guessing its for making test cases for the app (If someone knows, do tell me and will update the project).

![Java](img/javafolders.png)

Res

The res folder is the real deal. This folder contains all the graphics+ui stuff of your app.

![Resources](img/resourcefolder.png)
  • Drawable This is where all images go. Real programmers create different sized of every image to reduce memory imprint on smaller devices, but i’m too lazy for that
  • Layout This folder contains the xmls that define the layout of each activity
  • Menu This folder stores all the menu options for various activities.
  • Values This one contains all defined constants such as colors, themes, paddings, strings, ints etc Usually its a good idea to make another xmls that stores all your API keys and also add it to the .gitignore so you don’t end up accidentally committing them

Gradle

This is where all the gradle files reside. Usually you’ll only be making small changes to the build.gradle in the App Module Other than that, its mostly left untouched

![Gradle](img/gradlefolder.png)

Layouts

Now lets head over the activity_main.xml content_main.xml and you’ll probably be brought the design GUI. From the left pane you can drag and drop objects onto the screen and the layout xml will automatically change to add the new item. Easy peasy stuff, but often annoying. And so we move onto the actual XML ->

activity_main.xml (text view)

So this XML is where your layout is defined. This file is used to define the outer structure of the activity. Going through it line by line we have :

  • <?xml
    • This is the xml version and encoding of the file.
  • <CoordinatorLayout
    • This is the declaration of the layout, which in this case is the Coordinator Layout. As the name suggests, this type of layout is to coordinate the movement of various views inside and moving the views in relation to each other. For example, you can make the toolbar shorter as you scroll down etc.