android app development 11-20-2013 - clarkson universityjsearlem/cs242/fa13/lectures/35.adt.pdf ·...

28
Android App Development 11-20-2013

Upload: others

Post on 03-Jun-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices

Android App Development

11-20-2013

Page 4: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices
Page 5: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices

Applications The Android Open Source project contains several

default application, like the Browser, Camera, Gallery, Music, Phone and more.

Application framework API which allows for high-level interaction with the

Android system from Android applications.

Libraries and runtime Libraries for the Application Framework for many

functions (graphic rendering, data storage, web browsing, etc.) and the Dalvik runtime and the core Java libraries for running Android applications.

Linux kernel

Communication layer for the underlying hardware.

Page 6: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices

Android applications and tasks An Android application consists of different Android

components and additional resources. Components are: activities, services, broadcast receiver and content provider.

Android application components can connect to components of other Android applications to create tasks.

Android user interface components Activity, Fragments, Views and layout manager

Page 7: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices

Intents asynchronous message which allow the app to requrest

functionality from other Android components, e.g. from services or activites

Services services perform tasks without a user interface

ContentProvider a content provider gives a structured interface to

application data, so your app can share data with other apps via a content provider. A SQLite database stores data which is accessed via a content provider.

Widgets

interactive components primarily used on the homescreen

Live Wallpapers

Page 8: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices

Android SDK tools to create, compile and package an app

create Android virtual devices (AVD)

contains the Android debug bridge (adb) tool which has the ability to connect to a virtual or real Android device

Android Development Tools (ADT) create, compile, debug and deploy Android apps from

the Eclipse IDE

provides editors that allow you to switch between the XML representation of a file and a visual user interface via tabs on the bottom of the editor

Dalvik Virtual Machine Java class files must be converted to Dalvik bytecode

format (.dex); Android package (.apk)

Page 9: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices

Google vs. Android AVD

Device emulator shortcuts

Shortcut Description

Alt + Enter Maximizes the emulator

Ctrl + F11 Changes the orientation of the emulator from landscape to portrait and vice versa

F8 Turns the network on and off

Page 10: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices
Page 11: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices
Page 12: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices

Do not interrupt this startup process, since this might corrupt

the AVD.

Once started, don’t stop the AVD during your development.

Page 13: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices

Property Value

Application Name MyApp

Project Name edu.clarkson.cs242.myapp

Package Name edu.clarkson.cs242.myapp

API (minimum, target, …) latest

Page 14: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices
Page 15: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices
Page 16: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices

Right click on your project and select

Run as -> Android Application

May be prompted if ADT should monitor message - Yes

Page 17: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices
Page 18: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices

AndroidMainfest.xml

describes components and settings of an Android app

all activities, services and content providers of the app must be in this file; broadcast receiver can be defined statically in the manifest or dynamically in the app

also contains the required permissions for the app

if the app requires network access, must be specified in the manifest

Page 19: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="de.vogella.android.temperature"

android:versionCode="1"

android:versionName="1.0">

<application android:icon="@drawable/icon“

android:label="@string/app name">

<activity android:name=".Convert"

android:label="@string/app_name">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

<uses-sdk android:minSdkVersion="9" />

</manifest>

Page 20: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices

Resource Folder Description

Drawables /res/drawables Images (e.g. png, jpeg) or XML files which describe a drawable

Simple Values

/res/values define strings, colors, dimensions, styles and integers via XML viles. By convention each type is stored in a separate file. Strings are defined in res/values/strings.xml

Layouts /res/layout XML files with layout descriptions

Styles and Themes

/res/values define the appearance of your Android app

Animations /res/animator defines animations in XML

Raw data /res/raw data files in raw form, accessed via an InputStream

Menus /res/menu describes properties of menu entries

Page 21: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices

Every resource file gets an ID assigned by the Android build system

The gen directory in the project contains the R.java references file which contain these generated values

Methods are provided to access the resource files via these IDs

e.g. to access a String with the R.string.yourStringID, use

getString(R.string.yourString)

Page 22: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context=".MainActivity" >

<TextView android:id="@+id/mytext"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/hello_world" />

</RelativeLayout>

A layout resource file specifies the ViewGroup, Views

and their relationships and attributes in XML

Page 23: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices

A layout is assigned to an activity via the

setContentView() method

package com.vogella.android.first;

import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

}

Page 24: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices

Property Value

Application Name

Temperature converter

Project Name de.vogella.android.temperature

Package name de.vogella.android.temperature

API Latest

Template BlankActivity

Activity MainActivity

Layout activity_main

Page 25: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices

Select res/values/string.xml to open the editor for this file

Page 26: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices
Page 27: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices

<?xml version="1.0" encoding="utf-8"?>

<resources>

<string name="app_name">Temperature Converter</string>

<string name="action_settings">Settings</string>

<string name="hello_world">Hello world!</string>

<color name="myColor">#F5F5F5</color>

<string name="celsius">to Celsius</string>

<string name="fahrenheit">to Fahrenheit</string>

<string name="calc">Calculate</string>

</resources>

Continue with the tutorial to

complete the temperature app

Page 28: Android App Development 11-20-2013 - Clarkson Universityjsearlem/cs242/fa13/lectures/35.ADT.pdf · Android SDK tools to create, compile and package an app create Android virtual devices

Create an Android app to play the dice game “Pig”

cf: wikipedia & about.com for the rules