80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
Android activity
1. • What is an Activity?
• Application and Activity
• Task/ Activity Back Stack
• Activity Life Cycle
• Manifest file
2. • In a simple way it’s a single screen in your application.
• A Class that Provides a visual interface to allow the user to
interact with the application
• Every activity focus on one thing that user can do .
• For example
- registration screen
- login screen
- list of items
- watching media ( videos – pictures)
3. APPLICATION AND ACTIVITY .
• An application usually contains multiple activities
that user can navigate through to accomplish job.
• An Application can consist at least one activity it
depends on the application it self and it’s design
• For example if we have an e-mail app.
list of e-mails -> one activity
e-mail details -> another activity
compose new msg -> another activity
4. TASK/ACTIVITY BACK STACK
• Task is a set of related activity, it can span multiple
applications
• Starts with the home screen of the application
• Example
-if your application wants to send an email, you can define an
intent to perform a "send" action and include some data, such
as an email address and a message. An activity from another
application that declares itself to handle this kind of intent
then opens(i.e Gmail). In this case, the intent is to send an
email, so an email application's "compose" activity starts
- Sharing an image .
5. CONT.
• A task is a collection of activities that users interact with
when performing a certain job. The activities are arranged
in a stack (the "back stack"), in the order in which each
activity is opened.
• When the current activity starts another, the new activity
is pushed on the top of the stack and takes focus. The
previous activity remains in the stack, but is stopped. When
an activity stops, the system retains the current state of
its user interface. When the user presses
the Backbutton, the current activity is popped from the top
of the stack (the activity is destroyed) and the previous
activity resumes
7. ACTIVITY LIFE CYCLE.
• there are several situations in which an activity transitions
between different states
• Some lifecycle changes depending on
- user choice like pressing the back button
- android itself (i.e. memory running low )
• you probably don't need to implement all the lifecycle
methods. However, it's important that you understand each
one and implement those that ensure your app behaves the
way users expect , E.g. doesn’t crash while receiving phone
call , use resources well, don’t lose user progress
8. CONT.
• only three of these states can be static
1. ResumedIn, the activity is in the foreground and the user can
interact with it. (Also sometimes referred to as the "running"
state.)
2. PausedIn , the activity is partially obscured by another
activity—the other activity that's in the foreground is semi-
transparent or doesn't cover the entire screen. The paused
activity does not receive user input and cannot execute any
code.
3. StoppedIn, the activity is completely hidden and not visible to
the user; it is considered to be in the background. While
stopped, the activity instance and all its state information such
as member variables is retained, but it cannot execute any
code.
9. CONT.
• The other states (Created and Started) are transient and
the system quickly moves from them to the next state by
calling the next lifecycle callback method. That is, after the
system calls onCreate(), it quickly calls onStart(), which is
quickly followed by onResume().
10.
11. ACTIVITY CALLBACK METHODS
• ➤ onCreate() — Called when the activity is first created
• ➤ onStart() — Called when the activity becomes visible to the
user
• ➤ onResume() — Called when the activity starts interacting
with the user
• ➤ onPause() — Called when the current activity is being paused
and the previous activity is
• being resumed
• ➤ onStop() — Called when the activity is no longer visible to
the user
• ➤ onDestroy() — Called before the activity is destroyed by the
system
• ➤ onRestart() — Called when the activity has been stopped and
is restarting again
12. ACTIVITY LIFE CYCLE – ONCREATE()
• Called when Activity is created
• Sets up Initial state
• Call super.onCreate()
• Set the Activity’s content view
• Retain reference to UI views as necessary
• Configure views as necessary ( actions )
13. MANIFEST FILE
• Every Activity has to be declared In the manifest file – otherwise “ Activity Not Found”
error condition occurs