Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
Android App Development
11-20-2013
Android app development
Recommend: use the Eclipse+ADT bundle
Read:
http://developer.android.com
Building your first app
Dan Morrill (Clarkson grad)
PR#2 due: Wednesday, 12/04/13
Lars Vogel
www.vogella.com/articles/Android/article.html
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.
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
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
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)
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
Do not interrupt this startup process, since this might corrupt
the AVD.
Once started, don’t stop the AVD during your development.
Property Value
Application Name MyApp
Project Name edu.clarkson.cs242.myapp
Package Name edu.clarkson.cs242.myapp
API (minimum, target, …) latest
Right click on your project and select
Run as -> Android Application
May be prompted if ADT should monitor message - Yes
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
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>
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
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)
<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
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);
}
}
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
Select res/values/string.xml to open the editor for this file
<?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
Create an Android app to play the dice game “Pig”
cf: wikipedia & about.com for the rules