Download Application Lifecycle

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Transcript
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
the calendar of dates
• Devo displays a single
devotion
Intent myIntent = new Intent(AdventDevos.this, Devo.class);
myIntent.putExtra("ButtonNum", "" + index);
startActivity(myIntent);
Two Activities in Advent Devotions
• AdventDevos displays
the calendar of dates
• Devo displays a single
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
URL
• Browser launched
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"
Specifies icon for launching app
android:versionName="1.0">
<application android:icon="@drawable/star" android:label="@string/app_name" android:debug
<activity android:name=".AdventDevos"
android:label="@string/app_name">
Specifies icon for launching app
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Devo"/>
</application>
Specifies activity to be launched at startup
<uses-sdk android:minSdkVersion="3" />
<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>
Similar