Slide 1

Slide 1 text

1 / 89 PPTB (ET-4044) Android Programming Basics Eueung Mulyana https://eueung.github.io/012017/android1 CodeLabs | Attribution-ShareAlike CC BY-SA

Slide 2

Slide 2 text

Outline Android & Android Studio App Development Building Your First App 2 / 89

Slide 3

Slide 3 text

Notes Android Studio 2.3.3 (Stable Channel) A copy of the latest OpenJDK comes bundled with Android Studio 2.2 and higher, and this is the JDK version recommended for your Android projects. Ref: [Con gure Android Studio] 3 / 89

Slide 4

Slide 4 text

Android & Android Studio 4 / 89

Slide 5

Slide 5 text

5 / 89 What is Android Mobile operating system based on Linux kernel User Interface for touch screens Used on over 80% of all smartphones Powers devices such as watches, TVs, and cars Over 2 Million Android apps in Google Play store Highly customizable for devices / by vendors Open source Ref: Android Developer Fundamentals

Slide 6

Slide 6 text

Android Versions 6 / 89

Slide 7

Slide 7 text

7 / 89 Android Studio + Android SDK O cial Android IDE Develop, run, debug, test, and package apps Monitors and performance tools Virtual devices Project views Visual layout editor Ref: Android Developer Fundamentals

Slide 8

Slide 8 text

8 / 89 Logical Areas 1. Toolbar 2. Navigation Bar 3. Editor Window 4. Tool Window Bar (Expand/Collapse) 5. Tool Window 6. Status Bar

Slide 9

Slide 9 text

9 / 89 Layout Editor Project Window (1) Palette of UI Elements (2) Selectors (3) Design Pane (6) Component Tree (7) Design/Text Tabs (8)

Slide 10

Slide 10 text

10 / 89 Layout Editor Properties Pane (4) Text Property of TextView (5)

Slide 11

Slide 11 text

App Development 11 / 89

Slide 12

Slide 12 text

12 / 89 Android App One or more interactive screens Written using Java Programming Language and XML (*) Uses the Android Software Development Kit (SDK) Uses Android libraries and Android Application Framework Executed by Android Runtime Virtual machine (ART) Ref: Android Developer Fundamentals

Slide 13

Slide 13 text

13 / 89 Android Challenges Multiple screen sizes and resolutions Performance: make your apps responsive and smooth Security: keep source code and user data safe Compatibility: run well on older platform versions Marketing: understand the market and your users (Hint: It doesn't have to be expensive, but it can be.)

Slide 14

Slide 14 text

14 / 89 App Building Blocks Resources: layouts, images, strings, colors as XML and media les Components: activities, services,... and helper classes as Java code Manifest: information about app for the runtime Build con guration: APK versions in Gradle con g les

Slide 15

Slide 15 text

15 / 89 Component Types Activity is a single screen with a user interface Service performs long-running tasks in background Content provider manages shared set of data Broadcast receiver responds to system-wide announcements

Slide 16

Slide 16 text

16 / 89 Think of Android as a Hotel Your App is the guest The Android System is the hotel manager Services are available when you request them (Intents) In the foreground (Activities) such as registration In the background (Services) such as laundry Calls you when a package has arrived (Broadcast Receiver) Access the city's tour companies (Content Provider) Ref: Android Developer Fundamentals

Slide 17

Slide 17 text

Android Studio Building Your First App 17 / 89

Slide 18

Slide 18 text

18 / 89 Building Your First App 1. Create an Android Project 2. Run Your App 3. Build a Simple User Interface 4. Start Another Activity

Slide 19

Slide 19 text

Create an Android Project 19 / 89

Slide 20

Slide 20 text

Start a New Project 20 / 89

Slide 21

Slide 21 text

Adjust Application name (& Company domain) 21 / 89

Slide 22

Slide 22 text

Set Target Devices 22 / 89

Slide 23

Slide 23 text

Co ee Time ... (If SDK components not yet locally available) 23 / 89

Slide 24

Slide 24 text

Add Empty Activity 24 / 89

Slide 25

Slide 25 text

Adjust Activity Name (& Layout Name) 25 / 89

Slide 26

Slide 26 text

Project Window | app>java> ... >MainActivity.java 26 / 89

Slide 27

Slide 27 text

app>res>layout>activity_main.xml (Design View) 27 / 89

Slide 28

Slide 28 text

app>res>layout>activity_main.xml (Text View) 28 / 89

Slide 29

Slide 29 text

app>manifests>AndroidManifest.xml 29 / 89

Slide 30

Slide 30 text

@string/app_name 30 / 89

Slide 31

Slide 31 text

@string/app_name 31 / 89

Slide 32

Slide 32 text

Run Your App On an Emulator | On a Real Device 32 / 89

Slide 33

Slide 33 text

Launch AVD Manager 33 / 89

Slide 34

Slide 34 text

Create Virtual Device 34 / 89

Slide 35

Slide 35 text

Select Hardware | Phone 35 / 89

Slide 36

Slide 36 text

Download System Image (If it's not already there) 36 / 89

Slide 37

Slide 37 text

Co ee Time ... 37 / 89

Slide 38

Slide 38 text

Select System Image 38 / 89

Slide 39

Slide 39 text

Verify -> Finish 39 / 89

Slide 40

Slide 40 text

Launch this AVD in the Emulator 40 / 89

Slide 41

Slide 41 text

AVD Launched 41 / 89

Slide 42

Slide 42 text

Run the App 42 / 89

Slide 43

Slide 43 text

Select Target 43 / 89

Slide 44

Slide 44 text

Showtime! 44 / 89

Slide 45

Slide 45 text

Run Your App On an Emulator | On a Real Device 45 / 89

Slide 46

Slide 46 text

46 / 89 USB Debugging Settings>General >About Device Note: Titles may vary!

Slide 47

Slide 47 text

47 / 89 USB Debugging Build Number

Slide 48

Slide 48 text

48 / 89 USB Debugging Build Number | Tap 7x!

Slide 49

Slide 49 text

49 / 89 USB Debugging Settings>Developer Options

Slide 50

Slide 50 text

50 / 89 USB Debugging Settings>Developer Options | USB Debugging Note: Titles may vary!

Slide 51

Slide 51 text

Run | Select Target 51 / 89

Slide 52

Slide 52 text

52 / 89 Done! Installed on the Device

Slide 53

Slide 53 text

Build a Simple User Interface 53 / 89

Slide 54

Slide 54 text

Show Blueprint, Show Constraints, Autoconnect O & Default Margin 16 54 / 89

Slide 55

Slide 55 text

Component Tree | Replace TextView with EditText | Adjust/Drag Constraint Anchors 55 / 89

Slide 56

Slide 56 text

Add Button | Adjust/Drag Constraint Anchors | Note: Baseline Constraint 56 / 89

Slide 57

Slide 57 text

Change the UI Strings | String Resources 57 / 89

Slide 58

Slide 58 text

Change the UI Strings | Translation Editor 58 / 89

Slide 59

Slide 59 text

Properties | @string/edit_message (Remove text) 59 / 89

Slide 60

Slide 60 text

Properties | @string/button_send 60 / 89

Slide 61

Slide 61 text

Select Both | Center Horizontally 61 / 89

Slide 62

Slide 62 text

A Chain Between the Two Views 62 / 89

Slide 63

Slide 63 text

Button | Left & Right Margin ->16 63 / 89

Slide 64

Slide 64 text

Text | Left Margin ->16 | Width Indicator -> Match Constraints 64 / 89

Slide 65

Slide 65 text

activity_main.xml (Text) 65 / 89

Slide 66

Slide 66 text

Run & Test 66 / 89

Slide 67

Slide 67 text

Start Another Activity 67 / 89

Slide 68

Slide 68 text

sendMessage() Method Stub | Alt + Enter -> Import class 68 / 89

Slide 69

Slide 69 text

Connect sendMessage() to the Button 69 / 89

Slide 70

Slide 70 text

app | Create a New Empty Activity 70 / 89

Slide 71

Slide 71 text

DisplayMessageActivity 71 / 89

Slide 72

Slide 72 text

DisplayMessageActivity.java 72 / 89

Slide 73

Slide 73 text

MainActivity.java 73 / 89

Slide 74

Slide 74 text

activity_display_message.xml | textAppearance 74 / 89

Slide 75

Slide 75 text

Run & Test 75 / 89

Slide 76

Slide 76 text

AVD - Landscape 76 / 89

Slide 77

Slide 77 text

77 / 89 Run & Test Real Device | SM-N750

Slide 78

Slide 78 text

78 / 89 Run & Test Real Device | SM-N750

Slide 79

Slide 79 text

MainActivity.java | Di 79 / 89

Slide 80

Slide 80 text

package com.example.em.exampleapplication01; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.EditText; public class MainActivity extends AppCompatActivity { public static final String EXTRA_MESSAGE = "com.example.em.exampleapplication01.MESSAGE"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void sendMessage(View view) { Intent intent = new Intent(this, DisplayMessageActivity.class); EditText editText = (EditText) findViewById(R.id.editText); String message = editText.getText().toString(); intent.putExtra(EXTRA_MESSAGE, message); startActivity(intent); } } 80 / 89 MainActivity.java

Slide 81

Slide 81 text

package com.example.em.exampleapplication01; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; public class DisplayMessageActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_display_message); // Get the Intent that started this activity and extract the string Intent intent = getIntent(); String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE); // Capture the layout's TextView and set the string as its text TextView textView = (TextView) findViewById(R.id.textView); textView.setText(message); } } 81 / 89 DisplayMessageActivity.java

Slide 82

Slide 82 text

activity_main.xml | Di 82 / 89

Slide 83

Slide 83 text

83 / 89 activity_main.xml

Slide 84

Slide 84 text

84 / 89 activity_display_message.xml

Slide 85

Slide 85 text

AndroidManifest.xml | Di 85 / 89

Slide 86

Slide 86 text

86 / 89 AndroidManifest.xml

Slide 87

Slide 87 text

Refs/Resources 87 / 89

Slide 88

Slide 88 text

Refs/Resources 1. Getting Started | Android Developers 2. Dashboards | Android Developers 3. Android Developer Fundamentals | Google Developers Training | Google Developers 4. Introduction - Android Developer Fundamentals Course - Practicals 88 / 89

Slide 89

Slide 89 text

89 / 89 END Eueung Mulyana https://eueung.github.io/012017/android1 CodeLabs | Attribution-ShareAlike CC BY-SA