Stefan Forsström Department of Information and Communication Systems Mid Sweden University, Sundsvall, Sweden Android Development Crash Course Campus Sundsvall, 2015
Stefan Forsström Department of Information and Communication Systems
Mid Sweden University, Sundsvall, Sweden
Android Development
Crash Course
Campus Sundsvall, 2015
OVERVIEW
• The Android Platform
• Start Programming Applications
• Example Application
• Laboration
• Reference Material
2015-06-08 2 Stefan Forsström
The Android platform
THE ANDROID PLATFORM
• An operating system aimed for Smartphones – But also: Tablets, TV’s, Sensor motes, Gaming consoles, Watches, etc.
• Programming Languages – Java with Android extensions
• To code the functionality
– XML with graphical editor
• For designing the user interface
2015-06-08 4 Stefan Forsström
THE ANDROID PLATFORM
• Why choose Android? – The basics are the same for all different platforms
– So if you know Android, the change to iOS, Windows Phone, etc. is simple
• But we choose Android because – It’s free and open source! Just download and start coding
– It’s the most widespread! With over 900 million devices worldwide
– It’s in Java! Which is one of the most popular programming languages
– It’s easy to publish! Register as a developer and publish right away
2015-06-08 5 Stefan Forsström
Programming Applications
DOCUMENTATION • Most of it is accessible online
– http://developer.android.com/
• Design – Esthetic guidelines
• Develop – Programming oriented
• Distribute – Publishing process
2015-06-08 7 Stefan Forsström
INSTALLATION AND SETUP • If you want to develop Android apps on your own laptop
• Download Java JDK and run installer – http://www.oracle.com/technetwork/java/javase/downloads/index.html
• Install Android Studio with SDK – Download and install
– http://developer.android.com/sdk/index.html
• And then you are ready to code! – Start Android Studio
2015-06-08 8 Stefan Forsström
• Java Code
• XML Design
• XML Code
PROGRAMMING IN ANDROID STUDIO
2015-06-08 9 Stefan Forsström
Example Application
EXAMPLE
2015-06-08 11 Stefan Forsström
• Android XML Layout – res/layout/main.xml
• TextView
• ImageView
• 3 Buttons
EXAMPLE
2015-06-08 12 Stefan Forsström
• Java Code – src/MainActivity.java
• Register Listeners
• Handle OnClick
• Switch Button Id
• Change Image
EXAMPLE
2015-06-08 13 Stefan Forsström
• You now have a very simple “Cute Kittens” app! – The laboration will be to extend this app
Reference Material
ANDROID COMPONENTS • Activities
– An app can consists of many activities
– Can be seen as the different screens of an app
– Start Activity, Game Activity, HighScoreActivity, etc.
• Views – The stuff you see on the screen and can interact with
– ImageView, TextView, Button, etc.
• Layouts – Used for placing out views on the screen at a specific place
– LinearLayout, RelativeLayout, TableLayout, etc.
• Intents – Inform the OS on intentions to perform a specific task
– Start new activity, etc.
2015-06-08 15 Stefan Forsström
ACTIVITIES
• Activities form a flow chart of the application
• They are stored in the form of a stack – With the main activity at the bottom and the current activity on top
2015-06-08 16 Stefan Forsström
THE USER INTERFACE
• User Interface – Specified in an XML file
– Can be seen as a blueprint for the user interface
– Specifies what views should be seen and where they should appear
• But Android creates the components at run-time – When the XML file is parsed and interpreted
2015-06-08 17 Stefan Forsström
VIEWS
• Views – Are the components you see on the screen
– Each View can be given a unique ID
• One must find them, to make interaction from the code – FindViewById
2015-06-08 18 Stefan Forsström
LAYOUTS
• Layouts – Used for positioning Views on the screen
• Where and what something should be placed
• The most common Layouts – LinearLayout
• Horizontal or Vertical order of Views
– FrameLayout
• A stack of views, from the bottom up
– RelativeLayout
• View locations are specified in relation to each other, below, to the right of, etc.
– TableLayout
• Views are placed in a table, using row, columns, etc.
2015-06-08 19 Stefan Forsström
INTENTS
• Intents are used to make the Android OS do stuff for you – Typical example, start new activity
• The share intent – Probably the easiest way to share via social networks
2015-06-08 20 Stefan Forsström
MANIFEST
• The Android Manifest – A configuration file for your whole application
• Examples – The activities that exists within the application
• All activates must be listed
– Which activity to call when the app is started
• The “main” activity
– Overall graphical style
• Icon, Style, Theme, orientation, etc.
– Security permissions
• Internet, contacts, phone status, etc.
2015-06-08 21 Stefan Forsström
LISTENERS
• Listeners are used everywhere in Android – Because they are a standardized way of coding event handling
• Used for Buttons, Touches, etc. – Example:
2015-06-08 22 Stefan Forsström
MEDIA PLAYER
• Android has a multimedia framework – With support for playing most common media types
• You can play media files as resources (raw resources) – Located in the app res/raw folder
• Or from an URL, streaming over the Internet
2015-06-08 23 Stefan Forsström