SlideShare ist ein Scribd-Unternehmen logo
1 von 90
Downloaden Sie, um offline zu lesen
St. Pölten University of Applied SciencesSt. Pölten University of Applied Sciences
Platzhalter für möglichen
Bildeinsatz
Android Development with Kotlin, Part 1
Introduction
Andreas Jakl
Digital Healthcare
FH St. Pölten
Platzhalter für möglichen
Bildeinsatz
Version 1.3
Andreas Jakl
â–Ş Focus areas
â–Ş AR / VR, mobile apps, sensors, interaction
technology, software architecture, open source
developer (NFC, Bluetooth Beacons)
â–Ş Microsoft MVP (Most Valuable Professional)
â–Ş mobility.builders community: Mobile Developer
After-Work Events
â–Ş Previous Experience
â–Ş Tieto, Start-up (Mopius), Nokia (Finland),
Siemens Mobile (Munich), FH Hagenberg
(Mobile Computing)
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten
https://www.andreasjakl.com/
@andijakl
andreas.jakl@fhstp.ac.at
2
Contents
â–Ş Hybrid & Native Apps
â–Ş Native Android Development
â–Ş Android & SDK Versions
â–Ş Hello World
â–Ş Emulators, Devices & ADB
â–Ş Android Emulators & Build Process
â–Ş Kotlin Android Extensions
â–Ş App Lifecycle
â–Ş Saving App State
â–Ş Debugging
â–Ş Code Style + Documentation
â–Ş Activities & Intents
â–Ş Implicit Intents
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 3
Android Studio
â–Ş If you have not already:
â–Ş Install Android Studio now!
▪ It’ll take some time …
â–Ş https://developer.android.com/studio/index.html
â–Ş Already includes JDK
â–Ş Troubleshooting
â–Ş https://docs.google.com/document/d/1w1Xn_hnSAODAAtdRDp7haYPBtEwX
_l7Htpf8Wpgbu6w/pub?embedded=true
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 4
NATIVE APPS
Web vs Hybrid vs Native
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 5
Web vs Hybrid vs Native
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 6
Web Apps
Multi-platform
Web UI / UX
Run in browser (can be offline)
Slower performance
Less system integration
Native Apps
Single platform
Native UI / UX
Run directly on OS
Fast performance, best system
integration. More expensive.
Hybrid Apps
Multi-platform
Hybrid UI / UX
Parts in HTML, parts native
Web vs Hybrid vs Native
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 7
Web Apps
Native Apps
Hybrid Apps
Cost
User Experience
Additional Materials
â–Ş Free Android Courses by Google & Udacity
â–Ş Java Programming Basics: https://www.udacity.com/course/java-programming-
basics--ud282#
â–Ş Android Basics: User Interface: https://www.udacity.com/course/android-basics-
user-interface--ud834#
â–Ş Developing Android Apps: https://www.udacity.com/course/new-android-
fundamentals--ud851#
â–Ş Kotlin for Android Developers: https://www.udacity.com/course/kotlin-for-
android-developers--ud888
â–Ş Quick Kotlin overview for Java Android devs:
https://developer.android.com/kotlin/index.html
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 8
NATIVE ANDROID DEVELOPMENT
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 9
Android Development
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 10
Java Kotlin C++
Frame-
works
(Unity, Xamarin,
Qt, …)
Web
Android Studio
Visual Studio
Specific
tools
Visual
Studio
Code,
WebStorm,
etc.
IntelliJ IDEA
Android Web / Hybrid Apps
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 11
Image source: Google,
https://developer.android.com/guide/webapps/index.html
Android Web / Hybrid Apps
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 12
Cordova
Native
functionality
(Java, C++, …)
Image source: Google,
https://developer.android.com/guide/webapps/index.html
Cross-Platform Engines
â–Ş Usually specialized for app types
â–Ş Unity
â–Ş Games, 2D / 3D graphical apps
â–Ş Cross-platform
â–Ş Graphical editor, code with C#
â–Ş Xamarin
â–Ş Apps
â–Ş iOS, Android, Windows
â–Ş Cross-platform C# APIs, with Xamarin.Forms also UI. Specific native code possible
â–Ş Qt
â–Ş Apps and embedded
â–Ş Cross-platform
â–Ş UI with JavaScript / QML, native code with C++
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 13
Image sources:
Unity Logo, by Unity Technologies
Public domain, https://en.wikipedia.org/wiki/File:Unity_Technologies_Logo.svg
Xamarin Logo, by Xamarin Inc. / Microsoft
Public domain, https://en.wikipedia.org/wiki/File:Xamarin-logo.svg
Qt Logo, by The Qt Company
Public domain, https://en.wikipedia.org/wiki/File:Qt_logo_2016.svg
Android C++
â–Ş Native Development Kit (NDK)
â–Ş C and C++ code
â–Ş Why?
â–Ş Reuse existing C++ code & libraries
â–Ş Extra performance, less latency
â–Ş Combine: communication Java <> C++
â–Ş Java Native Interface (JNI)
â–Ş https://developer.android.com/ndk/guides/index.html
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 14
Image credits: logo for C++ created by Jeremy Kratz
Licensed for use of any purpose by the Standard C++ Foundatino
https://en.wikipedia.org/wiki/File:ISO_C%2B%2B_Logo.svg
Java (for Android)
â–Ş Java: Source code > Byte code > executed by Java Virtual Machine (JVM)
â–Ş License
â–Ş OpenJDK
â–Ş GPL v2 license
â–Ş De-facto reference implementation of Java by Oracle / Sun, basis for Oracle JDK
â–Ş Used in Android since Nougat
â–Ş Android uses recent Java. By default part of Android Studio: C:android-studiojre
â–Ş Trial Google vs. Oracle
â–Ş Use of Java = fair use? Switch to OpenJDK as a result
(before: Apache Harmony, re-implementation of copyrighted Java APIs)
â–Ş http://www.zdnet.com/article/oracle-vs-google-just-as-you-thought-java-android-row-was-over-it-all-kicks-off-again/
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 15
Image credits: Duke, the mascot used by Java.
Copyright Sun Microsystems Inc., BSD license
https://en.wikipedia.org/wiki/File:Duke_(Java_mascot)_waving.svg
Kotlin
▪ Programming language, “improved Java”
â–Ş Runs on Java JVM
â–Ş Interoperable with Java code + libraries
â–Ş Possible to mix Kotlin + Java in same project
â–Ş But can also be compiled to JavaScript + native (C)
â–Ş Created by JetBrains
â–Ş Open source language (Apache 2 license): https://github.com/JetBrains/kotlin
â–Ş https://kotlinlang.org/
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 16
Image credits: Kotlin Logo, by JetBrains.
https://commons.wikimedia.org/wiki/File:Kotlin-logo.svg
Kotlin & Android
â–Ş Android
â–Ş Integrated in Android Studio 3+
â–Ş Fully supported programming language for Android
â–Ş Kotlin Android Extensions:
https://kotlinlang.org/docs/tutorials/android-
plugin.html
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 17
Image credits: Kotlin Logo, by JetBrains.
https://commons.wikimedia.org/wiki/File:Kotlin-logo.svg
Android Studio
â–Ş Official IDE
▪ Customized from JetBrain’s IntelliJ IDEA
â–Ş Windows, Mac OS, Linux
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 18
ANDROID PLATFORM
Versions & Structure
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 19
Android Versions
â–Ş Version Distribution:
https://developer.android.com/about/dashboards/index.html#Platform
â–Ş More features in newer versions
â–Ş But: partly backported
â–Ş Reduces fragmentation
â–Ş Support Library (AppCompat)
â–Ş Google Play Services
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 20
Android Versions
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 21
SDK Versions
â–Ş MinSDK
â–Ş Lowest OS your app can run on
â–Ş Restricts features and APIs you can use
â–Ş TargetSDK
â–Ş Version you tested the app on
▪ Generally forward compatible: if behavior changes in new version, new Android will still “simulate” behavior
of old TargetSDK version (e.g., Runtime permissions with Android M)
â–Ş https://developer.android.com/reference/android/os/Build.VERSION_CODES.html
â–Ş Use the latest version when starting a new project
â–Ş CompileSDK
â–Ş Not part of the manifest, only relevant for developer
â–Ş Generally use latest version -> allows using latest APIs if needed
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 22
HELLO WORLD
Your First Android App
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 23
Create New Project
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 24
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 25
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 26
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 27
Project Structure
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 28
See: https://developer.android.com/studio/build/index.html
Views
â–Ş Android user interface (UI) composed of views
â–Ş TextView
â–Ş ImageView
â–Ş Button
â–Ş Etc.
â–Ş All managed by a layout
â–Ş Positioning of views on the screen
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 29
Design
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 30
TextView
ImageView
Button
Toggle: Design / Text (XML)
XML
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 31
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.andreasjakl.helloworld.MainActivity"
tools:layout_editor_absoluteY="81dp">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="@+id/textView"
app:layout_constraintStart_toStartOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:srcCompat="@android:drawable/btn_star_big_on" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:text="Button"
app:layout_constraintEnd_toEndOf="@+id/imageView"
app:layout_constraintStart_toStartOf="@+id/imageView"
app:layout_constraintTop_toBottomOf="@+id/imageView" />
</android.support.constraint.ConstraintLayout>
TextView
ImageView
Button
Activity & Views
▪ Activity’s onCreate():
â–Ş R class
â–Ş Dynamically identify contents in res folder
â–Ş setContentView()
â–Ş Inflates the layout XML file
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 32
setContentView(R.layout.activity_main)
SDK Manager
â–Ş Android Studio > File > Settings > Appearance &
Behavior > System Settings > Android SDK, or:
▪ Install all “SDK platforms” you need
â–Ş SDK Tools: ensure you have at least
â–Ş Android SDK Build-Tools
â–Ş Android Emulator
â–Ş Android SDK Platform-Tools
â–Ş Android SDK Tools
â–Ş Google Play Services
â–Ş Google USB Driver (on Windows)
â–Ş Intel x86 Emulator Accelerator (HAXM installer)
â–Ş Support Repository
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 33
Running the App
▪ Press “Play” arrow
â–Ş Select deployment target
â–Ş Connected phones or emulator
▪ “Create New Virtual Device”
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 34
Android Debug Bridge (ADB)
â–Ş ADB manages connections to phones & emulators
â–Ş Debugging
â–Ş Installing apps
â–Ş Windows: add to path (next slide)
▪ “adb.exe” usually in C:Androidplatform-tools
▪ Powershell: “adb devices –l” to show all connected devices
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 35
Emulator + phone connected
Windows: Add ADB to Environment Variables
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 36
Android Emulators
â–Ş Freely choose device configuration
â–Ş Screen size, OS, memory, etc.
â–Ş Hardware Acceleration
â–Ş Intel HAXM, but only for Intel. Conflict with Hyper-V
https://developer.android.com/studio/run/emulator-
acceleration.html#accel-vm
â–Ş Alternative: Microsoft Android emulator
https://www.visualstudio.com/vs/msft-android-
emulator/
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 37
Deploy to Android Phone
â–Ş Enable Developer Options
â–Ş Settings > (System) > About Phone > tap 7x on
“Build Number”
▪ Enable “USB debugging”
â–Ş Connect phone via USB
â–Ş Ensure debugging is active
▪ Device shows up in “adb devices”
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 38
Gradle
â–Ş Build automation system
â–Ş Used by Android Studio
â–Ş Can be run manually from command line
â–Ş Converts code to installable package
â–Ş Configuration: build.gradle
â–Ş You define: dependencies, versions, etc.
â–Ş https://developer.android.com/studio/build
/index.html
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 39
Image credits: Gradle Logo copyright Gradle, Inc.
Build process copyright Google,
https://developer.android.com/studio/build/index.html
Android Build Process
â–Ş Gradle settings
â–Ş settings.gradle (project root directory)
â–Ş Which modules to include. Usually only one line
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 40
include ':app'
Android Build Process
â–Ş Top-level build file
â–Ş build.gradle (project root directory)
â–Ş Applies to all modules
â–Ş buildscript: Gradle repositories &
dependencies
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 41
buildscript {
ext.kotlin_version = '1.2.10'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Android Build Process
â–Ş Module-level build file
â–Ş project/module/settings.gradle
â–Ş Only apply to this module
â–Ş Custom packaging options: Android options,
module-level dependencies, product flavors
(free / paid, …)
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 42
ADDING INTERACTIVITY
Hello World 2.0
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 43
Adapt Size & Color
â–Ş Check Google Material Design guidelines
â–Ş https://material.io/guidelines/
â–Ş Size
▪ View: use “dp” for device-independent pixels.
Same physical view size no matter the pixel density of the screen.
▪ Text: use “sp” for scale-independent pixels. Also considers user’s settings.
â–Ş Color
â–Ş Use color tool: https://material.io/color/
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 44
Improving XML Definitions
▪ Collect text in “res/values/strings.xml”
â–Ş Reference from TextView & Button
â–Ş Easier to localize and change
â–Ş Give useful IDs to elements
▪ Start with “@+id/”
▪ + indicates it’s a new resource ID
▪ Rename e.g., “@+id/textView” -> “@+id/tv_hello”
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 45
<TextView
android:id="@+id/tv_hello"
Interactivity with Kotlin for Android
â–Ş MainActivity.kt > Change TextView text when Button is clicked
â–Ş Create member variables to access UI elements
â–Ş In onCreate(), find views:
â–Ş Set click listener and change TextView text
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 46
private lateinit var mChangeTextButton : Button
private lateinit var mHelloTextView : TextView
mHelloTextView = findViewById(R.id.tv_hello)
mChangeTextButton = findViewById(R.id.bt_change)
mChangeTextButton.setOnClickListener {
mHelloTextView.text = "Welcome!"
}
Interactivity with Kotlin for Android
▪ Define “Welcome!” text in strings.xml and load from Kotlin code:
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 47
mChangeTextButton.setOnClickListener {
mHelloTextView.text = getText(R.string.welcome_text)
}
Kotlin Android Extensions
▪ findViewById() – easy to make errors, lots of code to write
â–Ş Kotlin Android Extensions make accessing views easier
â–Ş build.gradle: ensure the plugin is loaded
â–Ş MainActivity.kt: Add import with name of xml file
â–Ş Directly access View elements:
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 48
apply plugin: 'kotlin-android-extensions'
import kotlinx.android.synthetic.main.activity_main.*
bt_change.setOnClickListener {
tv_hello.text = getText(R.string.welcome_text)
}
Rotating the Screen?
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 49
?
Text switches
back to original
ANATOMY OF ANDROID APPS
Lifecycle
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 50
Android Application Components
1. Activity
▪ “Single focused thing the user can do”
â–Ş Creates view (to draw, based on XML layout file) and receives events (touch)
2. Service
3. Content Provider
4. Broadcast Receiver
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 51
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 52
Source:https://developer.android.com/guide/components/activities/activity-lifecycle.html
Task: Check Lifecycle
â–Ş Override all lifecycle methods of the activity
â–Ş Log status message (Log.d)
â–Ş Create TAG to recognize your log messages
â–Ş Example
â–Ş Check output in logcat
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 53
private val TAG = MainActivity::class.java.simpleName
override fun onStart() {
super.onStart()
Log.d(TAG, "onStart")
}
Task: Check Lifecycle
â–Ş Rotate screen!
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 54
Rotation
Saving the State
â–Ş Bundle for storing small amount of data
â–Ş Only used when resuming apps, not for re-starts
â–Ş Built-in for activity: save key-value pairs
â–Ş Key definition
â–Ş Save state
â–Ş Restore in onCreate() + default if not set
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 55
private val KEY_TEXT = "uiText"
override fun onSaveInstanceState(outState: Bundle?) {
outState?.putString(KEY_TEXT, tv_hello.text.toString())
super.onSaveInstanceState(outState)
}
if (savedInstanceState != null) {
tv_hello.text = savedInstanceState.getString(KEY_TEXT, getText(R.string.hello_text).toString())
}
DEBUGGING
Finding and Fixing Errors
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 56
Trigger Error
â–Ş Create unhandled exception in onCreate()
â–Ş App crashes on startup
▪ Check logcat (set log level to “Error”)
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 57
throw Exception("Error!")
Debugging Android Apps
â–Ş Set Breakpoints & use debugging tools
▪ Run app with “Debug” mode
â–Ş Break on any exception
▪ Run > View Breakpoints … >
Activate “Any Exception”
â–Ş may include lots of others too
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 58
Android Lint
▪ Static Code Analysis: Analyze > Inspect Code…
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 59
Issues with R Class / Unknown Error Source
▪ Recheck XML in your resource files (layouts, …)
â–Ş Android Studio might not highlight everything, e.g. some typos
â–Ş Clean project to rebuild from scratch
â–Ş Build > Clean Project
â–Ş Re-Sync project with Gradle
â–Ş Tools > Android > Sync Project with Gradle Files
â–Ş Run Android Lint
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 60
Exercise: Guess-a-Number
â–Ş Create UI with at least 3 views:
▪ EditText (“Plain Text” or “Number”), Button, TextView
â–Ş Put all user-visible text in strings.xml resource
â–Ş Phone thinks of random number [1..100]
â–Ş User enters number and taps button
â–Ş Phone tells if number was too low, too high or correct
â–Ş Bonus: also add number of tries to message
â–Ş Bonus: reset game and create new random number
â–Ş Bonus: handle screen rotation
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 61
CODE STYLE
Documentation & Naming Conventions
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 62
Naming Conventions
â–Ş Android naming conventions & more:
â–Ş https://android.github.io/kotlin-guides/style.html
â–Ş Generic Kotlin
â–Ş https://kotlinlang.org/docs/reference/coding-conventions.html
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 63
Naming Conventions
â–Ş Package names
â–Ş Always lowercase
â–Ş Classes / Objects
â–Ş Start with upper case letter, camel humps
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 64
package com.andreasjakl.helloworld
class MainActivity : AppCompatActivity() {
Naming Conventions
â–Ş Functions, properties, local variables
â–Ş Start with lower case letter, camel humps, no underscores
â–Ş Exception: constructors (-> same name as class, uppercase starting letter)
â–Ş Constants
â–Ş Uppercase, underscore-separated
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 65
var myCounter = 3
override fun onSaveInstanceState(outState: Bundle?) {
private val KEY_TEXT = "uiText"
Documenting Code
â–Ş Code comments
â–Ş Important for classes, methods and properties (especially public)
â–Ş Java: JavaDoc
▪ Kotlin: KDoc – https://kotlinlang.org/docs/reference/kotlin-doc.html
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 66
KDoc Syntax
â–Ş Add comment directly above class / function
â–Ş Starts with /** , ends with */
▪ Every documentation line has * at the beginning – not part of comment
â–Ş Block tags
â–Ş Parameters: @param <name>
â–Ş Returns: @return
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 67
Generate Documentation: Dokka
â–Ş Add dokka-android plugin to app build.gradle
▪ Add gradle task “dokka” to configure documentation
â–Ş See: https://github.com/Kotlin/dokka/blob/master/README.md
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 68
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'org.jetbrains.dokka-android'
dokka {
outputFormat = 'html'
outputDirectory = "$buildDir/javadoc"
}
Generate Documentation: Dokka
▪ Configure docker version and dependency in module’s build.gradle
▪ Run gradle task “dokka” in terminal
â–Ş gradlew dokka
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 69
buildscript {
ext.kotlin_version = '1.2.10'
ext.dokka_version = '0.9.15'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:${dokka_version}"
}
}
Generate Documentation: Dokka
â–Ş Generated HTML documentation in app/build/javadoc directory:
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 70
ACTIVITIES
Adding multiple pages to your app
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 71
Our Task: Passing Data
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 72
Navigation
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 73
Activity Activity
not called directly
Indirect Triggering
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 74
Activity Activity
Intents
Flexibility: Launch Various Tasks
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 75
Activity Activity
Start new
Intents
Take picture
Open browser
What is an Intent?
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 76
- Message object
- Request action from other app component
- Can include data (extras)
Image source: Android Developer Guide
https://developer.android.com/guide/components/intents-filters.html
Exercise: Create Main Activity
â–Ş Name: GreetingApp
â–Ş UI
â–Ş TextView, EditText, Button
â–Ş Use helpful ids
â–Ş Externalize text to strings.xml
â–Ş Ensure proper dynamic layout
â–Ş Use setOnClickListener() on button
â–Ş Display entered text with a toast
â–Ş Search for documentation!
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 77
Exercise: Create Greeting Activity
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 78
Exercise: UI for Greeting Activity
â–Ş UI
â–Ş 2x TextView with helpful IDs
â–Ş Check AndroidManifest.xml
â–Ş Shows second activity
▪ It’s not configured for MAIN / LAUNCHER
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 79
Context
â–Ş Global information about app environment
â–Ş Provided by Android system
â–Ş Access app-specific resources
â–Ş App-level operations (e.g., launching activities)
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 80
Create & Launch Intent
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 81
val welcomeIntent = Intent(this, GreetingActivity::class.java)
startActivity(welcomeIntent)
Context Activity to start
Start!
Passing Data
â–Ş Intents support extended data
â–Ş Key / Value-based
â–Ş Default Intent.EXTRA_TEXT for passing basic String data
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 82
welcomeIntent.putExtra(Intent.EXTRA_TEXT, et_name.text.toString())
Text from EditText
Receiving Extra Data
â–Ş Activity has intent property
â–Ş Provides access to details about Intent
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 83
// Check if the calling intent actually provided EXTRA_TEXT data
if (intent.hasExtra(Intent.EXTRA_TEXT)) {
// Retrieve String contents from EXTRA_TEXT data
var userName = intent.getStringExtra(Intent.EXTRA_TEXT)
// Apply the String to the UI
tv_name.text = userName
}
Enable Back Navigation Arrow
â–Ş Specify parent activity in manifest
â–Ş Add meta-data if targeting Android 4.0
â–Ş For newer versions, the parentActivityName is enough
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 84
<activity android:name=".GreetingActivity"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
Implicit Intent
â–Ş Action to be done + (optional) data
â–Ş Take picture
â–Ş Call contact
â–Ş Show web page
▪ …
â–Ş Multiple apps can handle intent?
â–Ş Android lets user choose
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 85
Activity
Start new
Take picture
Open browser
Open Web Site
â–Ş Common Intents
â–Ş https://developer.android.com/guide/components/
intents-common.html
â–Ş -> Web Browser
â–Ş Extend UI
â–Ş Second button
â–Ş Click listener
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 86
Resolving Intents
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 87
// Target address, converted from String to URI
val webPage = Uri.parse("https://www.andreasjakl.com/")
// Create an intent. ACTION_VIEW is generic to show data to the user
// Apps can subscribe to handle specific URIs
// See: https://developer.android.com/reference/android/content/Intent.html#ACTION_VIEW
val webIntent = Intent(Intent.ACTION_VIEW, webPage)
// Check if at least one app is installed to handle our intent
if (webIntent.resolveActivity(packageManager) != null) {
// If yes, start the activity!
startActivity(webIntent)
}
URI?
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 88
scheme:[//[user[:password]@]host[:port]][/path][?query][#fragment]
https://www.andreasjakl.com/
mailto:andreas.jakl@fhstp.ac.at?subject=Android
geo:48.214643,15.6224716
spotify:album:3hrSH1h42tH4W1ods3Cm7o
Exercise
â–Ş Launch another common intent
â–Ş https://developer.android.com/guide/components/intents-common.html
â–Ş Examples
â–Ş Map
â–Ş Share
â–Ş Email
â–Ş Camera
â–Ş Note: some activities need extra permissions in your manifest!
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 89
THANK YOU!
Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 90

Weitere ähnliche Inhalte

Was ist angesagt?

Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show fileSaurabh Tripathi
 
Parceable serializable
Parceable serializableParceable serializable
Parceable serializableSourabh Sahu
 
Android Development with Kotlin course
Android Development  with Kotlin courseAndroid Development  with Kotlin course
Android Development with Kotlin courseGoogleDevelopersLeba
 
Api presentation
Api presentationApi presentation
Api presentationTiago Cardoso
 
Kotlin presentation
Kotlin presentation Kotlin presentation
Kotlin presentation MobileAcademy
 
Jetpack Compose.pptx
Jetpack Compose.pptxJetpack Compose.pptx
Jetpack Compose.pptxGDSCVJTI
 
Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)Ahsanul Karim
 
Flutter tutorial for Beginner Step by Step
Flutter tutorial for Beginner Step by StepFlutter tutorial for Beginner Step by Step
Flutter tutorial for Beginner Step by StepChandramouli Biyyala
 
Jetpack Compose.pdf
Jetpack Compose.pdfJetpack Compose.pdf
Jetpack Compose.pdfSumirVats
 
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017Hardik Trivedi
 
Flutter beyond hello world
Flutter beyond hello worldFlutter beyond hello world
Flutter beyond hello worldAhmed Abu Eldahab
 
Mobile application development
Mobile application developmentMobile application development
Mobile application developmentEric Cattoir
 
Introduction to Android Develpment
Introduction to Android DevelpmentIntroduction to Android Develpment
Introduction to Android DevelpmentNikhilPawar932560
 
Kotlin Jetpack Tutorial
Kotlin Jetpack TutorialKotlin Jetpack Tutorial
Kotlin Jetpack TutorialSimplilearn
 
Declarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeDeclarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeRamon Ribeiro Rabello
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React NativeAmazon Web Services
 
Kotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptxKotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptxtakshilkunadia
 

Was ist angesagt? (20)

Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show file
 
Parceable serializable
Parceable serializableParceable serializable
Parceable serializable
 
Android Development with Kotlin course
Android Development  with Kotlin courseAndroid Development  with Kotlin course
Android Development with Kotlin course
 
Api presentation
Api presentationApi presentation
Api presentation
 
Kotlin
KotlinKotlin
Kotlin
 
Kotlin presentation
Kotlin presentation Kotlin presentation
Kotlin presentation
 
Jetpack Compose.pptx
Jetpack Compose.pptxJetpack Compose.pptx
Jetpack Compose.pptx
 
Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)
 
Flutter tutorial for Beginner Step by Step
Flutter tutorial for Beginner Step by StepFlutter tutorial for Beginner Step by Step
Flutter tutorial for Beginner Step by Step
 
Jetpack Compose.pdf
Jetpack Compose.pdfJetpack Compose.pdf
Jetpack Compose.pdf
 
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
 
Flutter beyond hello world
Flutter beyond hello worldFlutter beyond hello world
Flutter beyond hello world
 
Mobile application development
Mobile application developmentMobile application development
Mobile application development
 
Introduction to Android Develpment
Introduction to Android DevelpmentIntroduction to Android Develpment
Introduction to Android Develpment
 
Kotlin Jetpack Tutorial
Kotlin Jetpack TutorialKotlin Jetpack Tutorial
Kotlin Jetpack Tutorial
 
Declarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeDeclarative UIs with Jetpack Compose
Declarative UIs with Jetpack Compose
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
 
Android ppt
Android ppt Android ppt
Android ppt
 
Kotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptxKotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptx
 
Flutter
FlutterFlutter
Flutter
 

Ă„hnlich wie Android Development with Kotlin, Part 1 - Introduction

Android Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSONAndroid Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSONAndreas Jakl
 
Android Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App ManagementAndroid Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App ManagementAndreas Jakl
 
Building a scalable app factory with Appcelerator Platform
Building a scalable app factory with Appcelerator PlatformBuilding a scalable app factory with Appcelerator Platform
Building a scalable app factory with Appcelerator PlatformAngus Fox
 
Android study jams
Android study jamsAndroid study jams
Android study jamsGDSCIIITR
 
Introducing: Ionic Studio & Appflow A Better Way to Build Apps
Introducing: Ionic Studio & Appflow A Better Way to Build AppsIntroducing: Ionic Studio & Appflow A Better Way to Build Apps
Introducing: Ionic Studio & Appflow A Better Way to Build AppsIonic Framework
 
Kotlin native for iOS and Android
Kotlin native for iOS and AndroidKotlin native for iOS and Android
Kotlin native for iOS and AndroidShady Selim
 
Appcelerator Titanium - An Introduction to the Titanium Ecosystem
Appcelerator Titanium - An Introduction to the Titanium EcosystemAppcelerator Titanium - An Introduction to the Titanium Ecosystem
Appcelerator Titanium - An Introduction to the Titanium EcosystemBoydlee Pollentine
 
Android Unplugged Event GDSC MJCET .pptx
Android Unplugged Event GDSC MJCET .pptxAndroid Unplugged Event GDSC MJCET .pptx
Android Unplugged Event GDSC MJCET .pptxMohdAbdulAleem4
 
Angular JS 2_0 BCS CTO_in_Res V3
Angular JS 2_0 BCS CTO_in_Res V3Angular JS 2_0 BCS CTO_in_Res V3
Angular JS 2_0 BCS CTO_in_Res V3Bruce Pentreath
 
Tren Pengembangan Aplikasi Android di 2021 - Ahmad Arif Faizin
Tren Pengembangan Aplikasi Android di 2021 - Ahmad Arif FaizinTren Pengembangan Aplikasi Android di 2021 - Ahmad Arif Faizin
Tren Pengembangan Aplikasi Android di 2021 - Ahmad Arif FaizinDicodingEvent
 
Accelerate Your IoT and Robotics Development Using Web Technology and Apache ...
Accelerate Your IoT and Robotics Development Using Web Technology and Apache ...Accelerate Your IoT and Robotics Development Using Web Technology and Apache ...
Accelerate Your IoT and Robotics Development Using Web Technology and Apache ...Intel® Software
 
Kotlin vs flutter which is better for doing business
Kotlin vs flutter  which is better for doing business Kotlin vs flutter  which is better for doing business
Kotlin vs flutter which is better for doing business Concetto Labs
 
Why to Choose Kotlin in 2023 to Build Mobile Apps Faster?
Why to Choose Kotlin in 2023 to Build Mobile Apps Faster?Why to Choose Kotlin in 2023 to Build Mobile Apps Faster?
Why to Choose Kotlin in 2023 to Build Mobile Apps Faster?9 series
 
THE WORLD OF HYBRID APP DEVELOPMENT
THE WORLD OF HYBRID APP DEVELOPMENTTHE WORLD OF HYBRID APP DEVELOPMENT
THE WORLD OF HYBRID APP DEVELOPMENTIRJET Journal
 
[OW2con19] LemonLDAP::NG success stories
[OW2con19] LemonLDAP::NG success stories[OW2con19] LemonLDAP::NG success stories
[OW2con19] LemonLDAP::NG success storiesWorteks
 
LemonLDAP::NG Success Stories presented at OW2con'19, June 12-13, Paris.
LemonLDAP::NG Success Stories presented at OW2con'19, June 12-13, Paris. LemonLDAP::NG Success Stories presented at OW2con'19, June 12-13, Paris.
LemonLDAP::NG Success Stories presented at OW2con'19, June 12-13, Paris. OW2
 
Android training
Android trainingAndroid training
Android trainingCusen Systems
 
Industry trend of HTML5 in 2012 (2012년 HTML5 총정리)
Industry trend of HTML5 in 2012 (2012년 HTML5 총정리)Industry trend of HTML5 in 2012 (2012년 HTML5 총정리)
Industry trend of HTML5 in 2012 (2012년 HTML5 총정리)Wonsuk Lee
 
What is Kotlin Multiplaform? Why & How?
What is Kotlin Multiplaform? Why & How? What is Kotlin Multiplaform? Why & How?
What is Kotlin Multiplaform? Why & How? Shady Selim
 
Tiggr Mobile Apps Builder at Silicon Valley HTML5 Group Meetup
Tiggr Mobile Apps Builder at Silicon Valley HTML5 Group MeetupTiggr Mobile Apps Builder at Silicon Valley HTML5 Group Meetup
Tiggr Mobile Apps Builder at Silicon Valley HTML5 Group MeetupMax Katz
 

Ă„hnlich wie Android Development with Kotlin, Part 1 - Introduction (20)

Android Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSONAndroid Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSON
 
Android Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App ManagementAndroid Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App Management
 
Building a scalable app factory with Appcelerator Platform
Building a scalable app factory with Appcelerator PlatformBuilding a scalable app factory with Appcelerator Platform
Building a scalable app factory with Appcelerator Platform
 
Android study jams
Android study jamsAndroid study jams
Android study jams
 
Introducing: Ionic Studio & Appflow A Better Way to Build Apps
Introducing: Ionic Studio & Appflow A Better Way to Build AppsIntroducing: Ionic Studio & Appflow A Better Way to Build Apps
Introducing: Ionic Studio & Appflow A Better Way to Build Apps
 
Kotlin native for iOS and Android
Kotlin native for iOS and AndroidKotlin native for iOS and Android
Kotlin native for iOS and Android
 
Appcelerator Titanium - An Introduction to the Titanium Ecosystem
Appcelerator Titanium - An Introduction to the Titanium EcosystemAppcelerator Titanium - An Introduction to the Titanium Ecosystem
Appcelerator Titanium - An Introduction to the Titanium Ecosystem
 
Android Unplugged Event GDSC MJCET .pptx
Android Unplugged Event GDSC MJCET .pptxAndroid Unplugged Event GDSC MJCET .pptx
Android Unplugged Event GDSC MJCET .pptx
 
Angular JS 2_0 BCS CTO_in_Res V3
Angular JS 2_0 BCS CTO_in_Res V3Angular JS 2_0 BCS CTO_in_Res V3
Angular JS 2_0 BCS CTO_in_Res V3
 
Tren Pengembangan Aplikasi Android di 2021 - Ahmad Arif Faizin
Tren Pengembangan Aplikasi Android di 2021 - Ahmad Arif FaizinTren Pengembangan Aplikasi Android di 2021 - Ahmad Arif Faizin
Tren Pengembangan Aplikasi Android di 2021 - Ahmad Arif Faizin
 
Accelerate Your IoT and Robotics Development Using Web Technology and Apache ...
Accelerate Your IoT and Robotics Development Using Web Technology and Apache ...Accelerate Your IoT and Robotics Development Using Web Technology and Apache ...
Accelerate Your IoT and Robotics Development Using Web Technology and Apache ...
 
Kotlin vs flutter which is better for doing business
Kotlin vs flutter  which is better for doing business Kotlin vs flutter  which is better for doing business
Kotlin vs flutter which is better for doing business
 
Why to Choose Kotlin in 2023 to Build Mobile Apps Faster?
Why to Choose Kotlin in 2023 to Build Mobile Apps Faster?Why to Choose Kotlin in 2023 to Build Mobile Apps Faster?
Why to Choose Kotlin in 2023 to Build Mobile Apps Faster?
 
THE WORLD OF HYBRID APP DEVELOPMENT
THE WORLD OF HYBRID APP DEVELOPMENTTHE WORLD OF HYBRID APP DEVELOPMENT
THE WORLD OF HYBRID APP DEVELOPMENT
 
[OW2con19] LemonLDAP::NG success stories
[OW2con19] LemonLDAP::NG success stories[OW2con19] LemonLDAP::NG success stories
[OW2con19] LemonLDAP::NG success stories
 
LemonLDAP::NG Success Stories presented at OW2con'19, June 12-13, Paris.
LemonLDAP::NG Success Stories presented at OW2con'19, June 12-13, Paris. LemonLDAP::NG Success Stories presented at OW2con'19, June 12-13, Paris.
LemonLDAP::NG Success Stories presented at OW2con'19, June 12-13, Paris.
 
Android training
Android trainingAndroid training
Android training
 
Industry trend of HTML5 in 2012 (2012년 HTML5 총정리)
Industry trend of HTML5 in 2012 (2012년 HTML5 총정리)Industry trend of HTML5 in 2012 (2012년 HTML5 총정리)
Industry trend of HTML5 in 2012 (2012년 HTML5 총정리)
 
What is Kotlin Multiplaform? Why & How?
What is Kotlin Multiplaform? Why & How? What is Kotlin Multiplaform? Why & How?
What is Kotlin Multiplaform? Why & How?
 
Tiggr Mobile Apps Builder at Silicon Valley HTML5 Group Meetup
Tiggr Mobile Apps Builder at Silicon Valley HTML5 Group MeetupTiggr Mobile Apps Builder at Silicon Valley HTML5 Group Meetup
Tiggr Mobile Apps Builder at Silicon Valley HTML5 Group Meetup
 

Mehr von Andreas Jakl

Create Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented RealityCreate Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented RealityAndreas Jakl
 
AR / VR Interaction Development with Unity
AR / VR Interaction Development with UnityAR / VR Interaction Development with Unity
AR / VR Interaction Development with UnityAndreas Jakl
 
Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)Andreas Jakl
 
Basics of Web Technologies
Basics of Web TechnologiesBasics of Web Technologies
Basics of Web TechnologiesAndreas Jakl
 
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & MoreBluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & MoreAndreas Jakl
 
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?Andreas Jakl
 
Mobile Test Automation
Mobile Test AutomationMobile Test Automation
Mobile Test AutomationAndreas Jakl
 
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...Andreas Jakl
 
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows PhoneWinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows PhoneAndreas Jakl
 
Nokia New Asha Platform Developer Training
Nokia New Asha Platform Developer TrainingNokia New Asha Platform Developer Training
Nokia New Asha Platform Developer TrainingAndreas Jakl
 
Windows Phone 8 NFC Quickstart
Windows Phone 8 NFC QuickstartWindows Phone 8 NFC Quickstart
Windows Phone 8 NFC QuickstartAndreas Jakl
 
Windows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App ScenariosWindows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App ScenariosAndreas Jakl
 
Windows 8 Platform NFC Development
Windows 8 Platform NFC DevelopmentWindows 8 Platform NFC Development
Windows 8 Platform NFC DevelopmentAndreas Jakl
 
NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)Andreas Jakl
 
06 - Qt Communication
06 - Qt Communication06 - Qt Communication
06 - Qt CommunicationAndreas Jakl
 
05 - Qt External Interaction and Graphics
05 - Qt External Interaction and Graphics05 - Qt External Interaction and Graphics
05 - Qt External Interaction and GraphicsAndreas Jakl
 
04 - Qt Data
04 - Qt Data04 - Qt Data
04 - Qt DataAndreas Jakl
 
03 - Qt UI Development
03 - Qt UI Development03 - Qt UI Development
03 - Qt UI DevelopmentAndreas Jakl
 
02 - Basics of Qt
02 - Basics of Qt02 - Basics of Qt
02 - Basics of QtAndreas Jakl
 
Basics of WRT (Web Runtime)
Basics of WRT (Web Runtime)Basics of WRT (Web Runtime)
Basics of WRT (Web Runtime)Andreas Jakl
 

Mehr von Andreas Jakl (20)

Create Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented RealityCreate Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented Reality
 
AR / VR Interaction Development with Unity
AR / VR Interaction Development with UnityAR / VR Interaction Development with Unity
AR / VR Interaction Development with Unity
 
Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)
 
Basics of Web Technologies
Basics of Web TechnologiesBasics of Web Technologies
Basics of Web Technologies
 
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & MoreBluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
 
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
 
Mobile Test Automation
Mobile Test AutomationMobile Test Automation
Mobile Test Automation
 
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
 
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows PhoneWinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
 
Nokia New Asha Platform Developer Training
Nokia New Asha Platform Developer TrainingNokia New Asha Platform Developer Training
Nokia New Asha Platform Developer Training
 
Windows Phone 8 NFC Quickstart
Windows Phone 8 NFC QuickstartWindows Phone 8 NFC Quickstart
Windows Phone 8 NFC Quickstart
 
Windows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App ScenariosWindows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App Scenarios
 
Windows 8 Platform NFC Development
Windows 8 Platform NFC DevelopmentWindows 8 Platform NFC Development
Windows 8 Platform NFC Development
 
NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)
 
06 - Qt Communication
06 - Qt Communication06 - Qt Communication
06 - Qt Communication
 
05 - Qt External Interaction and Graphics
05 - Qt External Interaction and Graphics05 - Qt External Interaction and Graphics
05 - Qt External Interaction and Graphics
 
04 - Qt Data
04 - Qt Data04 - Qt Data
04 - Qt Data
 
03 - Qt UI Development
03 - Qt UI Development03 - Qt UI Development
03 - Qt UI Development
 
02 - Basics of Qt
02 - Basics of Qt02 - Basics of Qt
02 - Basics of Qt
 
Basics of WRT (Web Runtime)
Basics of WRT (Web Runtime)Basics of WRT (Web Runtime)
Basics of WRT (Web Runtime)
 

KĂĽrzlich hochgeladen

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

KĂĽrzlich hochgeladen (20)

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Android Development with Kotlin, Part 1 - Introduction

  • 1. St. Pölten University of Applied SciencesSt. Pölten University of Applied Sciences Platzhalter fĂĽr möglichen Bildeinsatz Android Development with Kotlin, Part 1 Introduction Andreas Jakl Digital Healthcare FH St. Pölten Platzhalter fĂĽr möglichen Bildeinsatz Version 1.3
  • 2. Andreas Jakl â–Ş Focus areas â–Ş AR / VR, mobile apps, sensors, interaction technology, software architecture, open source developer (NFC, Bluetooth Beacons) â–Ş Microsoft MVP (Most Valuable Professional) â–Ş mobility.builders community: Mobile Developer After-Work Events â–Ş Previous Experience â–Ş Tieto, Start-up (Mopius), Nokia (Finland), Siemens Mobile (Munich), FH Hagenberg (Mobile Computing) Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten https://www.andreasjakl.com/ @andijakl andreas.jakl@fhstp.ac.at 2
  • 3. Contents â–Ş Hybrid & Native Apps â–Ş Native Android Development â–Ş Android & SDK Versions â–Ş Hello World â–Ş Emulators, Devices & ADB â–Ş Android Emulators & Build Process â–Ş Kotlin Android Extensions â–Ş App Lifecycle â–Ş Saving App State â–Ş Debugging â–Ş Code Style + Documentation â–Ş Activities & Intents â–Ş Implicit Intents Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 3
  • 4. Android Studio â–Ş If you have not already: â–Ş Install Android Studio now! â–Ş It’ll take some time … â–Ş https://developer.android.com/studio/index.html â–Ş Already includes JDK â–Ş Troubleshooting â–Ş https://docs.google.com/document/d/1w1Xn_hnSAODAAtdRDp7haYPBtEwX _l7Htpf8Wpgbu6w/pub?embedded=true Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 4
  • 5. NATIVE APPS Web vs Hybrid vs Native Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 5
  • 6. Web vs Hybrid vs Native Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 6 Web Apps Multi-platform Web UI / UX Run in browser (can be offline) Slower performance Less system integration Native Apps Single platform Native UI / UX Run directly on OS Fast performance, best system integration. More expensive. Hybrid Apps Multi-platform Hybrid UI / UX Parts in HTML, parts native
  • 7. Web vs Hybrid vs Native Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 7 Web Apps Native Apps Hybrid Apps Cost User Experience
  • 8. Additional Materials â–Ş Free Android Courses by Google & Udacity â–Ş Java Programming Basics: https://www.udacity.com/course/java-programming- basics--ud282# â–Ş Android Basics: User Interface: https://www.udacity.com/course/android-basics- user-interface--ud834# â–Ş Developing Android Apps: https://www.udacity.com/course/new-android- fundamentals--ud851# â–Ş Kotlin for Android Developers: https://www.udacity.com/course/kotlin-for- android-developers--ud888 â–Ş Quick Kotlin overview for Java Android devs: https://developer.android.com/kotlin/index.html Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 8
  • 9. NATIVE ANDROID DEVELOPMENT Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 9
  • 10. Android Development Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 10 Java Kotlin C++ Frame- works (Unity, Xamarin, Qt, …) Web Android Studio Visual Studio Specific tools Visual Studio Code, WebStorm, etc. IntelliJ IDEA
  • 11. Android Web / Hybrid Apps Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 11 Image source: Google, https://developer.android.com/guide/webapps/index.html
  • 12. Android Web / Hybrid Apps Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 12 Cordova Native functionality (Java, C++, …) Image source: Google, https://developer.android.com/guide/webapps/index.html
  • 13. Cross-Platform Engines â–Ş Usually specialized for app types â–Ş Unity â–Ş Games, 2D / 3D graphical apps â–Ş Cross-platform â–Ş Graphical editor, code with C# â–Ş Xamarin â–Ş Apps â–Ş iOS, Android, Windows â–Ş Cross-platform C# APIs, with Xamarin.Forms also UI. Specific native code possible â–Ş Qt â–Ş Apps and embedded â–Ş Cross-platform â–Ş UI with JavaScript / QML, native code with C++ Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 13 Image sources: Unity Logo, by Unity Technologies Public domain, https://en.wikipedia.org/wiki/File:Unity_Technologies_Logo.svg Xamarin Logo, by Xamarin Inc. / Microsoft Public domain, https://en.wikipedia.org/wiki/File:Xamarin-logo.svg Qt Logo, by The Qt Company Public domain, https://en.wikipedia.org/wiki/File:Qt_logo_2016.svg
  • 14. Android C++ â–Ş Native Development Kit (NDK) â–Ş C and C++ code â–Ş Why? â–Ş Reuse existing C++ code & libraries â–Ş Extra performance, less latency â–Ş Combine: communication Java <> C++ â–Ş Java Native Interface (JNI) â–Ş https://developer.android.com/ndk/guides/index.html Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 14 Image credits: logo for C++ created by Jeremy Kratz Licensed for use of any purpose by the Standard C++ Foundatino https://en.wikipedia.org/wiki/File:ISO_C%2B%2B_Logo.svg
  • 15. Java (for Android) â–Ş Java: Source code > Byte code > executed by Java Virtual Machine (JVM) â–Ş License â–Ş OpenJDK â–Ş GPL v2 license â–Ş De-facto reference implementation of Java by Oracle / Sun, basis for Oracle JDK â–Ş Used in Android since Nougat â–Ş Android uses recent Java. By default part of Android Studio: C:android-studiojre â–Ş Trial Google vs. Oracle â–Ş Use of Java = fair use? Switch to OpenJDK as a result (before: Apache Harmony, re-implementation of copyrighted Java APIs) â–Ş http://www.zdnet.com/article/oracle-vs-google-just-as-you-thought-java-android-row-was-over-it-all-kicks-off-again/ Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 15 Image credits: Duke, the mascot used by Java. Copyright Sun Microsystems Inc., BSD license https://en.wikipedia.org/wiki/File:Duke_(Java_mascot)_waving.svg
  • 16. Kotlin â–Ş Programming language, “improved Java” â–Ş Runs on Java JVM â–Ş Interoperable with Java code + libraries â–Ş Possible to mix Kotlin + Java in same project â–Ş But can also be compiled to JavaScript + native (C) â–Ş Created by JetBrains â–Ş Open source language (Apache 2 license): https://github.com/JetBrains/kotlin â–Ş https://kotlinlang.org/ Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 16 Image credits: Kotlin Logo, by JetBrains. https://commons.wikimedia.org/wiki/File:Kotlin-logo.svg
  • 17. Kotlin & Android â–Ş Android â–Ş Integrated in Android Studio 3+ â–Ş Fully supported programming language for Android â–Ş Kotlin Android Extensions: https://kotlinlang.org/docs/tutorials/android- plugin.html Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 17 Image credits: Kotlin Logo, by JetBrains. https://commons.wikimedia.org/wiki/File:Kotlin-logo.svg
  • 18. Android Studio â–Ş Official IDE â–Ş Customized from JetBrain’s IntelliJ IDEA â–Ş Windows, Mac OS, Linux Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 18
  • 19. ANDROID PLATFORM Versions & Structure Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 19
  • 20. Android Versions â–Ş Version Distribution: https://developer.android.com/about/dashboards/index.html#Platform â–Ş More features in newer versions â–Ş But: partly backported â–Ş Reduces fragmentation â–Ş Support Library (AppCompat) â–Ş Google Play Services Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 20
  • 21. Android Versions Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 21
  • 22. SDK Versions â–Ş MinSDK â–Ş Lowest OS your app can run on â–Ş Restricts features and APIs you can use â–Ş TargetSDK â–Ş Version you tested the app on â–Ş Generally forward compatible: if behavior changes in new version, new Android will still “simulate” behavior of old TargetSDK version (e.g., Runtime permissions with Android M) â–Ş https://developer.android.com/reference/android/os/Build.VERSION_CODES.html â–Ş Use the latest version when starting a new project â–Ş CompileSDK â–Ş Not part of the manifest, only relevant for developer â–Ş Generally use latest version -> allows using latest APIs if needed Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 22
  • 23. HELLO WORLD Your First Android App Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 23
  • 24. Create New Project Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 24
  • 25. Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 25
  • 26. Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 26
  • 27. Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 27
  • 28. Project Structure Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 28 See: https://developer.android.com/studio/build/index.html
  • 29. Views â–Ş Android user interface (UI) composed of views â–Ş TextView â–Ş ImageView â–Ş Button â–Ş Etc. â–Ş All managed by a layout â–Ş Positioning of views on the screen Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 29
  • 30. Design Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 30 TextView ImageView Button Toggle: Design / Text (XML)
  • 31. XML Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 31 <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.andreasjakl.helloworld.MainActivity" tools:layout_editor_absoluteY="81dp"> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" app:layout_constraintEnd_toEndOf="@+id/textView" app:layout_constraintStart_toStartOf="@+id/textView" app:layout_constraintTop_toBottomOf="@+id/textView" app:srcCompat="@android:drawable/btn_star_big_on" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginEnd="8dp" android:layout_marginTop="8dp" android:text="Button" app:layout_constraintEnd_toEndOf="@+id/imageView" app:layout_constraintStart_toStartOf="@+id/imageView" app:layout_constraintTop_toBottomOf="@+id/imageView" /> </android.support.constraint.ConstraintLayout> TextView ImageView Button
  • 32. Activity & Views â–Ş Activity’s onCreate(): â–Ş R class â–Ş Dynamically identify contents in res folder â–Ş setContentView() â–Ş Inflates the layout XML file Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 32 setContentView(R.layout.activity_main)
  • 33. SDK Manager â–Ş Android Studio > File > Settings > Appearance & Behavior > System Settings > Android SDK, or: â–Ş Install all “SDK platforms” you need â–Ş SDK Tools: ensure you have at least â–Ş Android SDK Build-Tools â–Ş Android Emulator â–Ş Android SDK Platform-Tools â–Ş Android SDK Tools â–Ş Google Play Services â–Ş Google USB Driver (on Windows) â–Ş Intel x86 Emulator Accelerator (HAXM installer) â–Ş Support Repository Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 33
  • 34. Running the App â–Ş Press “Play” arrow â–Ş Select deployment target â–Ş Connected phones or emulator â–Ş “Create New Virtual Device” Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 34
  • 35. Android Debug Bridge (ADB) â–Ş ADB manages connections to phones & emulators â–Ş Debugging â–Ş Installing apps â–Ş Windows: add to path (next slide) â–Ş “adb.exe” usually in C:Androidplatform-tools â–Ş Powershell: “adb devices –l” to show all connected devices Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 35 Emulator + phone connected
  • 36. Windows: Add ADB to Environment Variables Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 36
  • 37. Android Emulators â–Ş Freely choose device configuration â–Ş Screen size, OS, memory, etc. â–Ş Hardware Acceleration â–Ş Intel HAXM, but only for Intel. Conflict with Hyper-V https://developer.android.com/studio/run/emulator- acceleration.html#accel-vm â–Ş Alternative: Microsoft Android emulator https://www.visualstudio.com/vs/msft-android- emulator/ Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 37
  • 38. Deploy to Android Phone â–Ş Enable Developer Options â–Ş Settings > (System) > About Phone > tap 7x on “Build Number” â–Ş Enable “USB debugging” â–Ş Connect phone via USB â–Ş Ensure debugging is active â–Ş Device shows up in “adb devices” Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 38
  • 39. Gradle â–Ş Build automation system â–Ş Used by Android Studio â–Ş Can be run manually from command line â–Ş Converts code to installable package â–Ş Configuration: build.gradle â–Ş You define: dependencies, versions, etc. â–Ş https://developer.android.com/studio/build /index.html Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 39 Image credits: Gradle Logo copyright Gradle, Inc. Build process copyright Google, https://developer.android.com/studio/build/index.html
  • 40. Android Build Process â–Ş Gradle settings â–Ş settings.gradle (project root directory) â–Ş Which modules to include. Usually only one line Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 40 include ':app'
  • 41. Android Build Process â–Ş Top-level build file â–Ş build.gradle (project root directory) â–Ş Applies to all modules â–Ş buildscript: Gradle repositories & dependencies Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 41 buildscript { ext.kotlin_version = '1.2.10' repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.0.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } }
  • 42. Android Build Process â–Ş Module-level build file â–Ş project/module/settings.gradle â–Ş Only apply to this module â–Ş Custom packaging options: Android options, module-level dependencies, product flavors (free / paid, …) Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 42
  • 43. ADDING INTERACTIVITY Hello World 2.0 Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 43
  • 44. Adapt Size & Color â–Ş Check Google Material Design guidelines â–Ş https://material.io/guidelines/ â–Ş Size â–Ş View: use “dp” for device-independent pixels. Same physical view size no matter the pixel density of the screen. â–Ş Text: use “sp” for scale-independent pixels. Also considers user’s settings. â–Ş Color â–Ş Use color tool: https://material.io/color/ Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 44
  • 45. Improving XML Definitions â–Ş Collect text in “res/values/strings.xml” â–Ş Reference from TextView & Button â–Ş Easier to localize and change â–Ş Give useful IDs to elements â–Ş Start with “@+id/” â–Ş + indicates it’s a new resource ID â–Ş Rename e.g., “@+id/textView” -> “@+id/tv_hello” Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 45 <TextView android:id="@+id/tv_hello"
  • 46. Interactivity with Kotlin for Android â–Ş MainActivity.kt > Change TextView text when Button is clicked â–Ş Create member variables to access UI elements â–Ş In onCreate(), find views: â–Ş Set click listener and change TextView text Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 46 private lateinit var mChangeTextButton : Button private lateinit var mHelloTextView : TextView mHelloTextView = findViewById(R.id.tv_hello) mChangeTextButton = findViewById(R.id.bt_change) mChangeTextButton.setOnClickListener { mHelloTextView.text = "Welcome!" }
  • 47. Interactivity with Kotlin for Android â–Ş Define “Welcome!” text in strings.xml and load from Kotlin code: Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 47 mChangeTextButton.setOnClickListener { mHelloTextView.text = getText(R.string.welcome_text) }
  • 48. Kotlin Android Extensions â–Ş findViewById() – easy to make errors, lots of code to write â–Ş Kotlin Android Extensions make accessing views easier â–Ş build.gradle: ensure the plugin is loaded â–Ş MainActivity.kt: Add import with name of xml file â–Ş Directly access View elements: Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 48 apply plugin: 'kotlin-android-extensions' import kotlinx.android.synthetic.main.activity_main.* bt_change.setOnClickListener { tv_hello.text = getText(R.string.welcome_text) }
  • 49. Rotating the Screen? Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 49 ? Text switches back to original
  • 50. ANATOMY OF ANDROID APPS Lifecycle Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 50
  • 51. Android Application Components 1. Activity â–Ş “Single focused thing the user can do” â–Ş Creates view (to draw, based on XML layout file) and receives events (touch) 2. Service 3. Content Provider 4. Broadcast Receiver Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 51
  • 52. Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 52 Source:https://developer.android.com/guide/components/activities/activity-lifecycle.html
  • 53. Task: Check Lifecycle â–Ş Override all lifecycle methods of the activity â–Ş Log status message (Log.d) â–Ş Create TAG to recognize your log messages â–Ş Example â–Ş Check output in logcat Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 53 private val TAG = MainActivity::class.java.simpleName override fun onStart() { super.onStart() Log.d(TAG, "onStart") }
  • 54. Task: Check Lifecycle â–Ş Rotate screen! Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 54 Rotation
  • 55. Saving the State â–Ş Bundle for storing small amount of data â–Ş Only used when resuming apps, not for re-starts â–Ş Built-in for activity: save key-value pairs â–Ş Key definition â–Ş Save state â–Ş Restore in onCreate() + default if not set Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 55 private val KEY_TEXT = "uiText" override fun onSaveInstanceState(outState: Bundle?) { outState?.putString(KEY_TEXT, tv_hello.text.toString()) super.onSaveInstanceState(outState) } if (savedInstanceState != null) { tv_hello.text = savedInstanceState.getString(KEY_TEXT, getText(R.string.hello_text).toString()) }
  • 56. DEBUGGING Finding and Fixing Errors Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 56
  • 57. Trigger Error â–Ş Create unhandled exception in onCreate() â–Ş App crashes on startup â–Ş Check logcat (set log level to “Error”) Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 57 throw Exception("Error!")
  • 58. Debugging Android Apps â–Ş Set Breakpoints & use debugging tools â–Ş Run app with “Debug” mode â–Ş Break on any exception â–Ş Run > View Breakpoints … > Activate “Any Exception” â–Ş may include lots of others too Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 58
  • 59. Android Lint â–Ş Static Code Analysis: Analyze > Inspect Code… Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 59
  • 60. Issues with R Class / Unknown Error Source â–Ş Recheck XML in your resource files (layouts, …) â–Ş Android Studio might not highlight everything, e.g. some typos â–Ş Clean project to rebuild from scratch â–Ş Build > Clean Project â–Ş Re-Sync project with Gradle â–Ş Tools > Android > Sync Project with Gradle Files â–Ş Run Android Lint Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 60
  • 61. Exercise: Guess-a-Number â–Ş Create UI with at least 3 views: â–Ş EditText (“Plain Text” or “Number”), Button, TextView â–Ş Put all user-visible text in strings.xml resource â–Ş Phone thinks of random number [1..100] â–Ş User enters number and taps button â–Ş Phone tells if number was too low, too high or correct â–Ş Bonus: also add number of tries to message â–Ş Bonus: reset game and create new random number â–Ş Bonus: handle screen rotation Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 61
  • 62. CODE STYLE Documentation & Naming Conventions Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 62
  • 63. Naming Conventions â–Ş Android naming conventions & more: â–Ş https://android.github.io/kotlin-guides/style.html â–Ş Generic Kotlin â–Ş https://kotlinlang.org/docs/reference/coding-conventions.html Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 63
  • 64. Naming Conventions â–Ş Package names â–Ş Always lowercase â–Ş Classes / Objects â–Ş Start with upper case letter, camel humps Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 64 package com.andreasjakl.helloworld class MainActivity : AppCompatActivity() {
  • 65. Naming Conventions â–Ş Functions, properties, local variables â–Ş Start with lower case letter, camel humps, no underscores â–Ş Exception: constructors (-> same name as class, uppercase starting letter) â–Ş Constants â–Ş Uppercase, underscore-separated Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 65 var myCounter = 3 override fun onSaveInstanceState(outState: Bundle?) { private val KEY_TEXT = "uiText"
  • 66. Documenting Code â–Ş Code comments â–Ş Important for classes, methods and properties (especially public) â–Ş Java: JavaDoc â–Ş Kotlin: KDoc – https://kotlinlang.org/docs/reference/kotlin-doc.html Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 66
  • 67. KDoc Syntax â–Ş Add comment directly above class / function â–Ş Starts with /** , ends with */ â–Ş Every documentation line has * at the beginning – not part of comment â–Ş Block tags â–Ş Parameters: @param <name> â–Ş Returns: @return Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 67
  • 68. Generate Documentation: Dokka â–Ş Add dokka-android plugin to app build.gradle â–Ş Add gradle task “dokka” to configure documentation â–Ş See: https://github.com/Kotlin/dokka/blob/master/README.md Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 68 apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'org.jetbrains.dokka-android' dokka { outputFormat = 'html' outputDirectory = "$buildDir/javadoc" }
  • 69. Generate Documentation: Dokka â–Ş Configure docker version and dependency in module’s build.gradle â–Ş Run gradle task “dokka” in terminal â–Ş gradlew dokka Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 69 buildscript { ext.kotlin_version = '1.2.10' ext.dokka_version = '0.9.15' repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.0.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:${dokka_version}" } }
  • 70. Generate Documentation: Dokka â–Ş Generated HTML documentation in app/build/javadoc directory: Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 70
  • 71. ACTIVITIES Adding multiple pages to your app Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 71
  • 72. Our Task: Passing Data Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 72
  • 73. Navigation Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 73 Activity Activity not called directly
  • 74. Indirect Triggering Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 74 Activity Activity Intents
  • 75. Flexibility: Launch Various Tasks Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 75 Activity Activity Start new Intents Take picture Open browser
  • 76. What is an Intent? Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 76 - Message object - Request action from other app component - Can include data (extras) Image source: Android Developer Guide https://developer.android.com/guide/components/intents-filters.html
  • 77. Exercise: Create Main Activity â–Ş Name: GreetingApp â–Ş UI â–Ş TextView, EditText, Button â–Ş Use helpful ids â–Ş Externalize text to strings.xml â–Ş Ensure proper dynamic layout â–Ş Use setOnClickListener() on button â–Ş Display entered text with a toast â–Ş Search for documentation! Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 77
  • 78. Exercise: Create Greeting Activity Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 78
  • 79. Exercise: UI for Greeting Activity â–Ş UI â–Ş 2x TextView with helpful IDs â–Ş Check AndroidManifest.xml â–Ş Shows second activity â–Ş It’s not configured for MAIN / LAUNCHER Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 79
  • 80. Context â–Ş Global information about app environment â–Ş Provided by Android system â–Ş Access app-specific resources â–Ş App-level operations (e.g., launching activities) Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 80
  • 81. Create & Launch Intent Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 81 val welcomeIntent = Intent(this, GreetingActivity::class.java) startActivity(welcomeIntent) Context Activity to start Start!
  • 82. Passing Data â–Ş Intents support extended data â–Ş Key / Value-based â–Ş Default Intent.EXTRA_TEXT for passing basic String data Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 82 welcomeIntent.putExtra(Intent.EXTRA_TEXT, et_name.text.toString()) Text from EditText
  • 83. Receiving Extra Data â–Ş Activity has intent property â–Ş Provides access to details about Intent Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 83 // Check if the calling intent actually provided EXTRA_TEXT data if (intent.hasExtra(Intent.EXTRA_TEXT)) { // Retrieve String contents from EXTRA_TEXT data var userName = intent.getStringExtra(Intent.EXTRA_TEXT) // Apply the String to the UI tv_name.text = userName }
  • 84. Enable Back Navigation Arrow â–Ş Specify parent activity in manifest â–Ş Add meta-data if targeting Android 4.0 â–Ş For newer versions, the parentActivityName is enough Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 84 <activity android:name=".GreetingActivity" android:parentActivityName=".MainActivity"> <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".MainActivity" /> </activity>
  • 85. Implicit Intent â–Ş Action to be done + (optional) data â–Ş Take picture â–Ş Call contact â–Ş Show web page â–Ş … â–Ş Multiple apps can handle intent? â–Ş Android lets user choose Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 85 Activity Start new Take picture Open browser
  • 86. Open Web Site â–Ş Common Intents â–Ş https://developer.android.com/guide/components/ intents-common.html â–Ş -> Web Browser â–Ş Extend UI â–Ş Second button â–Ş Click listener Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 86
  • 87. Resolving Intents Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 87 // Target address, converted from String to URI val webPage = Uri.parse("https://www.andreasjakl.com/") // Create an intent. ACTION_VIEW is generic to show data to the user // Apps can subscribe to handle specific URIs // See: https://developer.android.com/reference/android/content/Intent.html#ACTION_VIEW val webIntent = Intent(Intent.ACTION_VIEW, webPage) // Check if at least one app is installed to handle our intent if (webIntent.resolveActivity(packageManager) != null) { // If yes, start the activity! startActivity(webIntent) }
  • 88. URI? Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 88 scheme:[//[user[:password]@]host[:port]][/path][?query][#fragment] https://www.andreasjakl.com/ mailto:andreas.jakl@fhstp.ac.at?subject=Android geo:48.214643,15.6224716 spotify:album:3hrSH1h42tH4W1ods3Cm7o
  • 89. Exercise â–Ş Launch another common intent â–Ş https://developer.android.com/guide/components/intents-common.html â–Ş Examples â–Ş Map â–Ş Share â–Ş Email â–Ş Camera â–Ş Note: some activities need extra permissions in your manifest! Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 89
  • 90. THANK YOU! Android Development with Kotlin, Part 1 | 2018 | Andreas Jakl | FH St. Pölten 90