1/42

Android Development

Android Introduction

2/42

Agenda

3/42

What is Android?

4/42

center 80%

Source: Google Blog

5/42

What is Android?

6/42

Short Android History

7/42

What comes with Android?

center

Source: giphy.com

8/42

Android Architecture

9/42

Android Platform Challenges

10/42

Android Platform Architecture

  • Based on Linux Kernel (v3.0 since Android 4.x)
  • Hardware Abstraction Layer providing standardized library modules for device’s harware
  • Android Runtime (ART) since v5.0 before, Dalvik VM
  • Native Libraries written in C/C++
  • Java API Framework for normal Android Apps
  • System Apps use the Java APIs
  • See: developer.android.com

60%

11/42

Dalvik VM / ART Optimizations

Optimization Effect
Combination of multiple Class files in one DEX file Smaller memory footprint, faster load of the application
Sharing of DEX files between processes (read-only mapping) Smaller memory footprint, faster load of the application
Byte ordering and word alignment according to local machine (install time) Faster load of the application DEX file itself still platform independent
Bytecode pre-verification (as much as possible, install time) Faster load and execution
Install-time optimization of bytecode Faster execution, still platform independence
Register instead of stack based virtual machine Faster execution (~30%)

See: http://sites.google.com/site/io/dalvik-vm-internals

12/42

Dex File Format

80%

13/42

Android Developer Toolchain

14/42

Android Studio Contains

15/42

Android Debug Bridge (adb)

> adb -e shell 
> adb push \<local> \<remote>
> adb pull \<remote> \[\<local>]
> adb install \<file>
16/42

Android Development Basics

17/42

Android Manifest

18/42

Android Manifest Structure

<?xml version="1.0" encoding="utf-8"?>
<manifest>
    <uses-permission />
	<application>
        <activity>
            <intent-filter>
                <action />
                <category />
                <data />
            </intent-filter>
            <meta-data />
        </activity>
         <service>
            <intent-filter> . . . </intent-filter>
            <meta-data/>
        </service>
	</application>
</manifest>
19/42

Android Manifest Example

center 80%

20/42

Android Layouts

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>
21/42

Android Layouts

Design Pattern Hint: Composite

22/42

Android Layouts

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_layout);
}
23/42

Android Layouts

<Button android:id="@+id/my_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/my_button_text"/>
Button myButton = (Button)findViewById(R.id.my_button);
24/42

Android Layouts

25/42

Android Layouts

ConstraintLayout

100%

A ConstraintLayout is a android.view.ViewGroup which allows you to position and size widgets in a flexible way.

Linear Layout

A layout that organizes its children into a single horizontal or vertical row. It creates a scrollbar if the length of the window exceeds the length of the screen.

Relative Layout

source: android

Enables you to specify the location of child objects relative to each other (child A to the left of child B) or to the parent (aligned to the top of the parent).

26/42

Android Layouts

<Button
        android:id="@+id/button"
        android:layout_width="113dp"
        android:layout_height="101dp"
        android:background="@android:drawable/ic_input_add"
        android:text="@string/ButtonText" />
27/42

Android Resources

28/42

Defining Alternative Resources

29/42

Android Resources

  1. Create a new directory in res/ named in the form <resources_name>-<config_qualifier>

    • <resources_name> is the directory name of the corresponding default resources
    • <qualifier> is a name that specifies an individual configuration for which these resources are to be used
    • More than one qualifier can be appended, but the order must be correct
  2. Save the respective alternative resources in this new directory. The resource files must be named exactly the same as the default resource files

30/42

Android Resources

res/
    drawable/   
        icon.png
        background.png    
    drawable-hdpi/  
        icon.png
        background.png 
31/42

Android Resources - Density Independent Design

center

32/42

Android Resources - Density Independent Design

center

33/42

Android Resources - Density Independent Design

float densityFactor = getResources().getDisplayMetrics().density;
34/42

Android Resources

public final class R {
...
public static final class layout {
    public static final int activity_main=0x7f030000;
}
public static final class mipmap {
    public static final int ic_launcher=0x7f020000;
    public static final int ic_launcher_round=0x7f020001;
}
public static final class string {
    public static final int ButtonText=0x7f050000;
    public static final int app_name=0x7f050001;
}
35/42

Android Resources

<Button
       android:id="@+id/button"
       ...
       />
36/42

Android Support Library

37/42

Android Support Library

38/42

Android Support Library

39/42

Android Build Process

  • Compilers convert source code into DEX files and resources into binary resources
  • DEX files and resources are combined in a APK
  • APK is signed using the debug or release keystore
  • APK is zipaligned to use less memory when running on a device by APK Packager
  • APK can be installed on device

60%

40/42

Android Build Process

41/42

Summary

42/42

Recab Questions