hello world - unr...4.build.gradle—gradle build files android developer fundamentals this work is...

28
Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License Create your first Android app Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License Create your first Android app Hello World Lesson 1 1 Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Upload: others

Post on 29-May-2020

17 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Hello World

Lesson 1

1

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Page 2: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

1.1 Create Your First Android App

2This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Page 3: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Contents

●Android Studio●Creating "Hello World" app in Android Studio●Basic app development workflow with Android

Studio●Running apps on virtual and physical devices

3

Page 4: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Prerequisites

●Java Programming Language●Object-oriented programming●XML - properties / attributes●Using an IDE for development and debugging

4

Page 5: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Android Studio

5This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Page 6: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

What is Android Studio?

6

l Android IDEl Project structurel Templatesl Layout Editorl Testing toolsl Gradle-based buildl Log Consolel Debuggerl Monitorsl Emulators

Page 7: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Installation Overview

●GNU/Linux, Mac, or Windows●Requires Java Development Kit (JDK) 1.7 or better

from Oracle Java SE downloads page●Set JAVA_HOME to JDK installation location●Download and install Android Studio from

http://developer.android.com/sdk/index.html●See 1.1 P Install Android Studio for details

7

Page 8: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Creating Your First Android App

8This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Page 9: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Start Android Studio

9

Page 10: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Create a project inside Android Studio

10

Page 11: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Name your app

11

Page 12: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Pick activity template

12

Choose templates for common activities, such as maps or navigation drawers.

Pick Empty Activity or Basic Activity for simple and custom activities.

Page 13: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Name your activity

13

l Good practice to name main activity MainActivity and activity_main layout

l Use AppCompatl Generating layout file

is convenient

Page 14: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app14

Project Files

Android Studio PanesLayout

Editor

Android Monitors:logcat: log messages

Page 15: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Project folders

15

1.manifests—Android Manifest file - description of app read by the Android runtime

2.java—Java source code packages3.res—Resources (XML) - layout,

strings, images, dimensions, colors...4.build.gradle—Gradle build files

Page 16: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Gradle build system

●Modern build subsystem in Android Studio●Three build.gradle:

○project○module○settings

●Typically not necessary to know low-level Gradle details

●Learn more about gradle at https://gradle.org/

16

Page 17: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Run your app

1717

1.Run

2. Select virtual or physical

device

3. OK

Page 18: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Create a virtual device

18

Use emulators to test app on different versions of Android and form factors.

Tools > Android > AVD Manager or:

Page 19: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Configure virtual device

19

1.Choose hardware 2. Select Android Version3. Finalize

Page 20: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Run on a virtual device

20

Page 21: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Run on a physical device

21

1.Turn on Developer Options: a.Settings > About phoneb.Tap Build number seven times

2.Turn on USB Debugginga.Settings > Developer Options > USB Debugging

3.Connect phone to computer with cable

Windows/Linux additional setup: l Using Hardware Devices

Windows drivers:l OEM USB Drivers

Page 22: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Get feedback as your app runs

●As the app runs, Android Monitor logcat shows information

●You can add logging statements to your app that will show up in logcat.

22

Page 23: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Loggingimport android.util.Log;

// Use class name as tagprivate static final String TAG = MainActivity.class.getSimpleName();

// Show message in Android Monitor, logcat pane// Log.<log-level>(TAG, "Message");Log.d(TAG, “Creating the URI…”);

23

Page 24: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Android Monitor > logcat pane

1.Log statements in code. 2.logcat pane shows

system and logging messages

24

●Set filters to see what's important to you●Search using tags

Page 25: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Learn more

●Meet Android Studio●Official Android documentation at

developer.android.com●Create and Manage Virtual Devices●Supporting Different Platform Versions●Supporting Multiple Screens

25

Page 26: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

Learn even more

●Gradle Wikipedia page●Google Java Programming Language style guide●Find answers at Stackoverflow.com

26

Page 27: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Create your first Android

app

What's Next?

27

●Concept Chapter: 1.1 C Create Your First Android App

●Practical: 1.1 P Install Android Studio and Run Hello World

Page 28: Hello World - UNR...4.build.gradle—Gradle build files Android Developer Fundamentals This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License

Android Developer Fundamentals

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License

Storing Data

END

28