Ac#vity is the basic building block of a mobile app interface. It represents a single screen with a user interface. An app uses Ac#vity classes to build a series of screens that the user can navigate between via intents. The Ac#vity lifecycle involves callback methods like onCreate, onStart, onResume etc that are important for initializing and releasing resources. Transi#ons between Ac#vi#es can be customized with anima#ons. Data can be passed between Ac#vi#es via intents and bundles. The manifest declares Ac#vi#es and their launch points and filters.
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 cant 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 e鍖ect your lifecycle as an Android App Developer as well
≒ Most of the Android Developer doesnt know about Lifecycle clearly and
that lead to apps quality problem
≒ Crash
≒ Malfunc$onal