2. [Recap] What is Ac#vity?
Ac$vity
Ac$vity class takes care of crea$ng a
window for you in which you can place
your UI
3. Introduc#on to Ac#vity
• Ac$vity is one of the core and key
system in Android
• Very important, you can’t just
know about it, you have to
MASTER at it
• Key message to fully understand:
• Lifecycle
4. Play around: Hide The Title Bar
1) Hide by Code
2) Hide by Style
Why do we hide it?
Live DemoCustom Title Bar No Title Bar at all
6. Naviga#on: The second Ac#vity
1) Create New Ac$vity
2) Try to startActivity
3) See what happened?
4) Play around with AndroidManifest.xml
5) Now try again
Live Demo
7. Intent
An Intent is a messaging object
you can use to request an ac$on
from another app component.
Live Demo
?
8. Lab: Intent & Bundle
Q: Why we need to send data through Intent?
A: Because Ac)vity is independent to each other
… Play Play Play …
9. Understand how Android OS works
• Secret: Actually Launcher
(Home Screen) is also an
Ac$vity !
• And launcher also launch
our applica$on through
Intent and startActivity
Live Demo
14. What do we do in each lifecycle event in prac#cal?
onCreate
Ini$alize UI Elements
onResume or onStart
Ini$alize System
Resources (GPS,
Camera, etc)
onDestroy
Mostly do nothing
onPause or onStop
Release System
Resources (GPS,
Camera, etc)
Stop CPU consuming
task like Anima$on,
Timer
Commit unsaved
changes
Pause Game
Why or?
22. Ac#vity Transi#on
• Basically transi$on will be done by default seengs
• But you can override it (but not so recommend unless it is by design)
• Example: <?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="2000" />
res/anim/fade_in.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha=“1.0" android:toAlpha=“0.0" android:duration="2000" />
res/anim/fade_out.xml
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
23. Recap
• Every$me you create a new Ac$vity, declare in AndroidManifest.xml
immediately
• Ac)vity Lifecycle is very very very important
• In can effect your lifecycle as an Android App Developer as well
• Most of the Android Developer doesn’t know about Lifecycle clearly and
that lead to app’s quality problem
• Crash
• Malfunc$onal