1/43

Lecture Mobile Application Development (119310)

Android Introduction

2/43

Agenda

3/43

What is Android?

4/43

center 60%

5/43

What is Android?

6/43

Short Android History

7/43

What comes with Android?

center

Image source: giphy.com

8/43

Android Architecture

9/43

Android Platform Challenges

10/43

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/43

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/43

Dex File Format

center

13/43

Android Developer Toolchain

14/43

Android Studio Contains

15/43

Android Debug Bridge (adb)


> adb -e shell 


> adb push \<local> \<remote>


> adb pull \<remote> \[\<local>]


> adb install \<file>

16/43

Android Development Basics

17/43

Android Manifest

18/43

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/43

Android Manifest Example

center 80%

20/43

Android Layouts


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical" >
    <TextView android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Hello, I am a TextView" />
    <Button android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello, I am a Button" />
</LinearLayout>

21/43

Android Layouts

Design Pattern Hint: Composite

22/43

Android Layouts


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

23/43

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/43

Android Layouts

25/43

Android Layouts

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/43

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/43

Android Resources

28/43

Defining Alternative Resources

29/43

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/43

Android Resources

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

Android Resources - Density Independent Design

center

32/43

Android Resources - Density Independent Design

center

33/43

Android Resources - Density Independent Design


float densityFactor = getResources().getDisplayMetrics().density;

34/43

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/43

Android Resources

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

Android Support Library

37/43

Android Support Library

38/43

Android Support Library

39/43

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/43

Android Build Process

41/43

Android Assignment #1

42/43

Summary

43/43

Recab Questions