Post on 02-Jun-2020
transcript
Android App Anatomy
EECS 4443 – Mobile User Interfaces
Scott MacKenzieYork University
© Scott MacKenzie
Android UIStatus Bar
Action Bar
Content Area
Navigation Bar
2© Scott MacKenzie
Android Application – In PartsFrom Studio's“Android” viewof the project…
• Project
• Module
• Manifest
• Package
• Source files
• Images (for app)
• XML layout
• String constants
• Build script
3© Scott MacKenzie
Source (.java) Files
4© Scott MacKenzie
Android Application – In PartsFrom Studio's“Android” viewof the project…
• Project
• Module
• Manifest
• Package
• Source files
• Images (for app)
• XML layout
• String constants
• Build script
5© Scott MacKenzie
Layout (.xml) Files
6© Scott MacKenzie
Layout (.xml) Files
7© Scott MacKenzie
Android Application – In PartsFrom Studio's“Android” viewof the project…
• Project
• Module
• Manifest
• Package
• Source files
• Images (for app)
• XML layout
• String constants
• Build script
8© Scott MacKenzie
String (.xml) Constants
9© Scott MacKenzie
Android Application – In PartsFrom Studio's“Android” viewof the project…
• Project
• Module
• Manifest
• Package
• Source files
• Images (for app)
• XML layout
• String constants
• Build script
10© Scott MacKenzie
What the heck is "manifest"?
• This is a reasonable question if you are new to Android programming
• Here's a simple way to answer this question (and other questions like this)
• Go to
and type "AndroidManifest.xml" in the search field ( )
© Scott MacKenzie11
developer.android.com
Manifest (.xml) File
12© Scott MacKenzie
No! (next slide)
minSDK, targetSDK
• Android projects are built to run on devices supporting a range of API levels
• API level determined in the project setup• Varies by IDE• Eclipse:
– Specified in AndroidManifest.xml via <uses-sdk> element (previous slide)
• Studio:– Specified in build.gradle (next slide)
© Scott MacKenzie13
Android Application – In PartsFrom Studio's“Android” viewof the project…
• Project
• Module
• Manifest
• Package
• Source files
• Images (for app)
• XML layout
• String constants
• Build script
14© Scott MacKenzie
build.gradle (Demo_Android)
© Scott MacKenzie15
API Levels (partial list)
© Scott MacKenzie16
http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
Changing minSDK & targetSDK
• How do you change the min/target API levels for an Android project using Studio?
1. Edit build.gradle2. Sync Project with Gradle Files ( )
• Or (preferred) …1. Right click on your project file ("app")2. Select "Open Module Settings"3. Go to the "Properties" tab and edit settings
1. A better question… How do you figure out stuff like this? (next slide)
© Scott MacKenzie17
StackOverflow to the Rescue
© Scott MacKenzie18
http://stackoverflow.com/questions/19465049/changing-api-level-android-studio
Android Package (.apk file)
19© Scott MacKenzie
From Studio's“Project” viewof the project…
Activities
20© Scott MacKenzie
Minimum Implementation
21© Scott MacKenzie
Activity Lifecycle
“Running”
22© Scott MacKenzie
ActivityLifecycle(more detail)
23© Scott MacKenzie
Activity Lifecycle Callbacks (1 of 2)
24© Scott MacKenzie
Activity Lifecycle Callbacks (2 of 2)
25© Scott MacKenzie
UI – Overview
26© Scott MacKenzie
UI – Overview
Examples:LinearLayoutRelativeLayoutTableLayout
Examples:TextViewButtonViewGroup
27© Scott MacKenzie
UI – Layout
28© Scott MacKenzie
UI – Layout
29© Scott MacKenzie
Layout Example (main.xml)
…30© Scott MacKenzie
Layout Example (main.xml)
…
Esc Let’s find out.
What’s the difference?
31© Scott MacKenzie
UI – Input Controls
32© Scott MacKenzie
UI – Input Events
33© Scott MacKenzie
UI – Event Listeners
34© Scott MacKenzie
Event Listener Example (onClick)
Note: main.xml has a Button element with android:id="@+id/mybutton" tag
35© Scott MacKenzie
Two Buttons!
36© Scott MacKenzie
Button Callbacks
• Two ways to setup… 1. Code (previous slide)
• Add implements OnClickListener to the signature of the activity
• Invoke setOnClickListener(this) on the Button instance
• Implement onClick(View v)• Example: Demo_Android, Demo_Layout
2. XML• Add android:onClick="buttonClick" as tag to
Button element in XML• Implement buttonClick(View v)• Example: Demo_Buttons
37© Scott MacKenzie
Demo Android
EscLet’s have a look.
38© Scott MacKenzie
Homework
• Review all notes in these slides– Do this by reading from the Android Developer
API Guide:
• Continue with Lab #1– Task 2, Task 3, …
© Scott MacKenzie39
http://developer.android.com/guide/index.html
The End(Actually, this is just the beginning!)
40© Scott MacKenzie