0% found this document useful (0 votes)
41 views

Android App Basics: Dr. David Janzen

This document provides an overview of the key concepts in developing an Android app, including: 1) It describes how the Advent Devotions app uses two activities - one to display a calendar and another to display individual devotions. Data is passed between activities using intents and extras. 2) It shows the app's AndroidManifest file which defines permissions, activities, and metadata. 3) It explains how layouts are defined in XML files and linked to activities, and how dimensions, colors and strings are stored in resource files.

Uploaded by

Majd Yassin
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Android App Basics: Dr. David Janzen

This document provides an overview of the key concepts in developing an Android app, including: 1) It describes how the Advent Devotions app uses two activities - one to display a calendar and another to display individual devotions. Data is passed between activities using intents and extras. 2) It shows the app's AndroidManifest file which defines permissions, activities, and metadata. 3) It explains how layouts are defined in XML files and linked to activities, and how dimensions, colors and strings are stored in resource files.

Uploaded by

Majd Yassin
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 13

Android App Basics

Dr. David Janzen

Except as otherwise noted, the content of this presentation is


licensed under the Creative Commons Attribution 2.5 License.
A First Example: Advent Devotions
UML Class Diagram

External Activity

Generated by Android
Two Activities in Advent Devotions
• AdventDevos displays • Devo displays a single
the calendar of dates devotion

Intent myIntent = new Intent(AdventDevos.this, Devo.class);


myIntent.putExtra("ButtonNum", "" + index);
startActivity(myIntent);
Two Activities in Advent Devotions
• AdventDevos displays • Devo displays a single
the calendar of dates devotion

Bundle extras = getIntent().getExtras();


String value = extras.getString("ButtonNum");
Integer buttonNum = Integer.valueOf(value);
Launching an Intent you didn’t write
• Devos has button to • Browser launched
URL

Intent i = new Intent(Intent.ACTION_VIEW,


Uri.parse("http://www.biblegateway.com/passage/?search="+
passage +"&version=NIV"));
startActivity(i);
Android Activity
• “An activity is a single, focused thing that
the user can do. Almost all activities
interact with the user, so the Activity class
takes care of creating a window for you in
which you can place your UI with
setContentView(View).”
http://developer.android.com/reference/android/app/
Activity.html#ActivityLifecycle
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> Each upload to Market requires versionCode increment
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.simexusa.adventdevotions"
android:versionCode="2"
android:versionName="1.0"> Specifies icon for launching app
<application android:icon="@drawable/star" android:label="@string/app_name" android:debug
<activity android:name=".AdventDevos"
android:label="@string/app_name">
<intent-filter> Specifies icon for launching app
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Devo"/>
</application>
<uses-sdk android:minSdkVersion="3" /> Specifies activity to be launched at startup
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Security permissions requested from user on install
Look around the files
Layouts and Resources
• See main.xml and devo.xml
– Activity associates with layout xml file using
setContentView(R.layout.main); or
setContentView(R.layout.devo); in onCreate()
– Note TableLayout and TableRow similar to
<table> and <tr> in html
– Note use of dimen (see values/dimens.xml) and
color (see values/colors.xml)
– Also see strings.xml
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@color/background">
<TableLayout android:layout_width="wrap_content"
android:id="@+id/TableLayout01" android:layout_height="wrap_content">
<TableRow android:paddingTop="8px">
<Button android:text="Nov. 29" android:id="@+id/Button01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="@dimen/button_width"></Button>
<Button android:text="Nov. 30" android:id="@+id/Button02"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="@dimen/button_width"></Button>
<Button android:text="Dec. 1" android:id="@+id/Button03"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="@dimen/button_width"></Button>
<Button android:text="Dec. 2" android:id="@+id/Button04"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="@dimen/button_width"></Button>
</TableRow> …
devo.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center_horizontal"
android:background="@color/background">
<TextView android:text="Date" android:id="@+id/Date"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="center_horizontal" android:textStyle="italic"
android:textSize="@dimen/reference_width" android:typeface="serif"
android:textColor="@color/text"></TextView>
<TextView android:text="Title" android:id="@+id/Title"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="center_horizontal" android:textStyle="bold"
android:textSize="@dimen/reference_width" android:typeface="serif"
android:textColor="@color/text"></TextView>
<Button android:text="Read Scripture" android:id="@+id/ButtonScripture"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="center_horizontal" android:textSize="@dimen/reference_width">
<ScrollView android:id="@+id/ScrollView01"
android:layout_height="fill_parent" android:layout_width="fill_parent">
dimens.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="button_width">17sp</dimen>
<dimen name="reference_width">20sp</dimen>
</resources>

colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="background">#AAFFFF99</color>
<color name="text">#FF000000</color>
</resources>

strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, AdventDevos!</string>
<string name="app_name">Advent Devotions</string>
</resources>

You might also like