android development crash courseapachepersonal.miun.se/~mageri/kurser/ipp/android/android...

24
Stefan Forsström Department of Information and Communication Systems Mid Sweden University, Sundsvall, Sweden Android Development Crash Course Campus Sundsvall, 2015

Upload: others

Post on 09-Sep-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

Stefan Forsström Department of Information and Communication Systems

Mid Sweden University, Sundsvall, Sweden

Android Development

Crash Course

Campus Sundsvall, 2015

Page 2: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

OVERVIEW

• The Android Platform

• Start Programming Applications

• Example Application

• Laboration

• Reference Material

2015-06-08 2 Stefan Forsström

Page 3: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

The Android platform

Page 4: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

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

Page 5: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

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

Page 6: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

Programming Applications

Page 7: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

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

Page 8: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

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

Page 9: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

• Java Code

• XML Design

• XML Code

PROGRAMMING IN ANDROID STUDIO

2015-06-08 9 Stefan Forsström

Page 10: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

Example Application

Page 11: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

EXAMPLE

2015-06-08 11 Stefan Forsström

• Android XML Layout – res/layout/main.xml

• TextView

• ImageView

• 3 Buttons

Page 12: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

EXAMPLE

2015-06-08 12 Stefan Forsström

• Java Code – src/MainActivity.java

• Register Listeners

• Handle OnClick

• Switch Button Id

• Change Image

Page 13: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

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

Page 14: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

Reference Material

Page 15: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

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

Page 16: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

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

Page 17: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

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

Page 18: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

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

Page 19: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

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

Page 20: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

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

Page 21: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

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

Page 22: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

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

Page 23: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

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

Page 24: Android Development Crash Courseapachepersonal.miun.se/~mageri/kurser/ipp/android/Android Civing.… · Android Development Crash Course Campus Sundsvall, 2015 . OVERVIEW • The

Contact

Dr. Stefan Forsström

E-Mail: [email protected]