SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
android activity
Activity
An Activity is an application component that provides a
screen with which users can interact in order to do
something, such as dial the phone, take a photo, send an
email, or view a map.
Each activity is given a window in which to draw its user
interface. The window typically fills the screen, but may
be smaller than the screen and float on top of other
windows.
Activity
An application usually consists of multiple activities that
are loosely bound to each other. Typically, one activity in
an application is specified as the "main" activity, which is
presented to the user when launching the application for
the first time. Each activity can then start another activity
in order to perform different actions.
Each time a new activity starts, the previous activity is
stopped, but the system preserves the activity in a stack .
When a new activity starts, it is pushed onto the back
stack and takes user focus.
Activity life cycle
Creating an Activity
To create an activity, you must create a subclass of
Activity (or an existing subclass of it). In your subclass,
you need to implement callback methods that the system
calls when the activity transitions between various states
of its lifecycle, such as when the activity is being created,
stopped, resumed, or destroyed. The two most important
callback methods are:
onCreate()
onPause()
Methods in Activity
onCreate() You must implement this method. The system
calls this when creating your activity. Within your
implementation, you should initialize the essential
components of your activity. Most importantly, this is
where you must call setContentView() to define the
layout for the activity's user interface.
onPause() The system calls this method as the first
indication that the user is leaving your activity (though it
does not always mean the activity is being destroyed).
This is usually where you should commit any changes that
should be persisted beyond the current user session .
There are several other lifecycle callback methods that
you should use in order to provide a fluid user experience
between activities and handle unexpected interuptions
that cause your activity to be stopped and even
destroyed. All of the lifecycle callback methods are
discussed later, in the section about Managing the
Activity Lifecycle.
onResume()
onStart()
onStop()
onDestroy()
onPause()
Other Methods
Sample Code
public class ExampleActivity extends Activity
{ Public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState); // The activity is being created.
}
Protected void onStart(){
super.onstart(); // The activity is about to become visible.
}
Protected void onPause(){
super.onPause(); // Another activity is taking focus (this activity is about to be
"paused"). }
Protected void onResume(){
super.onPause(); // The activity has become visible (it is now "resumed").
}
Protected void onstop(){
super.onPause(); // The activity is no longer visible (it is now "stopped")
}
Protected void onDestroy(){
super.onPause(); // The activity is about to be destroyed.
}
}
This is super class
For all classes
Declaring the activity in the manifest
You must declare your activity in the manifest file in
order for it to be accessible to the system. To
decalare your activity, open your manifest file and
add an <activity> element as a child of the
<application> element. For example:
<manifest ... >
<application ... >
<activity android: name=".ExampleActivity" />
...
</application ... >
...
</manifest >
Using intent filters
An <activity> element can also specify various intent
filters—using the <intent-filter> element—in order
to declare how other application components may
activate it.
• When you create a new application using the
Android SDK tools, the stub activity that's created
for you automatically includes an intent filter that
declares the activity responds to the "main" action
and should be placed in the "launcher" category.
The intent filter looks like this:
Using intent filters
<activity android:name=".ExampleActivity"
android:icon="@drawable/app_icon">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The <action> element
specifies that this is the
"main" entry point to the
application.
The <category> element specifies
that this activity should be listed in
the system's application launcher
(to allow users to launch this
activity).
Starting an Activity
You can start another activity by calling startActivity(),
passing it an Intent that describes the activity you
want to start. An intent can also carry small amounts
of data to be used by the activity that is started.
For example :
Intent intent = new Intent(this, Next. class);
intent.putExtra(“key”, value);
startActivity(intent);
Which is going
to be executed

More Related Content

PPTX
Android activity lifecycle
PDF
Android activities & views
ODP
Anatomy of android application
PDF
Introduction to fragments in android
PPTX
Android Services
PPTX
PPTX
Android Intent.pptx
PPTX
Presentation on Android application life cycle and saved instancestate
Android activity lifecycle
Android activities & views
Anatomy of android application
Introduction to fragments in android
Android Services
Android Intent.pptx
Presentation on Android application life cycle and saved instancestate

What's hot (20)

PPT
SQLITE Android
PDF
Android activity
PDF
Android intents
PDF
AndroidManifest
PPTX
Android UI
PPTX
Android User Interface
PDF
Android Components
PDF
UI controls in Android
PDF
Android Fragment
PDF
Android Threading
PPTX
Content provider in_android
PPT
android layouts
PDF
Introduction to Android Development
ZIP
Android Application Development
PPT
Object-oriented concepts
PDF
Layouts in android
PDF
Android life cycle
PPTX
Android share preferences
PDF
Android: Intent, Intent Filter, Broadcast Receivers
SQLITE Android
Android activity
Android intents
AndroidManifest
Android UI
Android User Interface
Android Components
UI controls in Android
Android Fragment
Android Threading
Content provider in_android
android layouts
Introduction to Android Development
Android Application Development
Object-oriented concepts
Layouts in android
Android life cycle
Android share preferences
Android: Intent, Intent Filter, Broadcast Receivers
Ad

Similar to android activity (20)

PPTX
Android activity
ODP
Android App Development - 02 Activity and intent
PPTX
Unit 5 Activity and Activity Life Cycle.pptx
PDF
Android development Training Programme Day 2
PDF
Android activity
PDF
Lecture 3 getting active through activities
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
DOCX
Android building blocks and application life cycle-chapter3
PDF
Android platform activity
PPTX
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
PPT
Android lifecycle
PPTX
Unit-1.2 Android-Activities, Fragments, and Intents (1).pptx
PDF
android_mod_3.useful for bca students for their last sem
PDF
02 programmation mobile - android - (activity, view, fragment)
PPTX
App Fundamentals and Activity life cycle.pptx
PPT
DOCX
Activity
DOCX
Activity
DOCX
Activity
DOCX
Activity
Android activity
Android App Development - 02 Activity and intent
Unit 5 Activity and Activity Life Cycle.pptx
Android development Training Programme Day 2
Android activity
Lecture 3 getting active through activities
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
Android building blocks and application life cycle-chapter3
Android platform activity
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
Android lifecycle
Unit-1.2 Android-Activities, Fragments, and Intents (1).pptx
android_mod_3.useful for bca students for their last sem
02 programmation mobile - android - (activity, view, fragment)
App Fundamentals and Activity life cycle.pptx
Activity
Activity
Activity
Activity
Ad

More from Deepa Rani (20)

PPT
Speed controller of dc motor
PPTX
Foot step power generator
PPTX
Crime investigation system
PPT
android content providers
PPTX
android sqlite
PPT
android menus
PPT
android dilaogs
PPT
android architecture,life cycle,sdk,execution process
PPTX
Android the first app - hello world - copy
PPTX
Android styles and themes
PPTX
Review of basic data structures
PPT
Blue Brain
PPTX
PPT
Dc machiness
PPT
Maddy android
PPTX
Fabric innovation
PPT
Typical problem
PPT
straight line
PPT
Section of solids
PPT
Projection of solids
Speed controller of dc motor
Foot step power generator
Crime investigation system
android content providers
android sqlite
android menus
android dilaogs
android architecture,life cycle,sdk,execution process
Android the first app - hello world - copy
Android styles and themes
Review of basic data structures
Blue Brain
Dc machiness
Maddy android
Fabric innovation
Typical problem
straight line
Section of solids
Projection of solids

Recently uploaded (20)

PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
RMMM.pdf make it easy to upload and study
PDF
01-Introduction-to-Information-Management.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Basic Mud Logging Guide for educational purpose
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Institutional Correction lecture only . . .
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
master seminar digital applications in india
PPTX
Microbial diseases, their pathogenesis and prophylaxis
102 student loan defaulters named and shamed – Is someone you know on the list?
RMMM.pdf make it easy to upload and study
01-Introduction-to-Information-Management.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Basic Mud Logging Guide for educational purpose
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Renaissance Architecture: A Journey from Faith to Humanism
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Institutional Correction lecture only . . .
STATICS OF THE RIGID BODIES Hibbelers.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Anesthesia in Laparoscopic Surgery in India
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
master seminar digital applications in india
Microbial diseases, their pathogenesis and prophylaxis

android activity

  • 2. Activity An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map. Each activity is given a window in which to draw its user interface. The window typically fills the screen, but may be smaller than the screen and float on top of other windows.
  • 3. Activity An application usually consists of multiple activities that are loosely bound to each other. Typically, one activity in an application is specified as the "main" activity, which is presented to the user when launching the application for the first time. Each activity can then start another activity in order to perform different actions. Each time a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack . When a new activity starts, it is pushed onto the back stack and takes user focus.
  • 5. Creating an Activity To create an activity, you must create a subclass of Activity (or an existing subclass of it). In your subclass, you need to implement callback methods that the system calls when the activity transitions between various states of its lifecycle, such as when the activity is being created, stopped, resumed, or destroyed. The two most important callback methods are: onCreate() onPause()
  • 6. Methods in Activity onCreate() You must implement this method. The system calls this when creating your activity. Within your implementation, you should initialize the essential components of your activity. Most importantly, this is where you must call setContentView() to define the layout for the activity's user interface. onPause() The system calls this method as the first indication that the user is leaving your activity (though it does not always mean the activity is being destroyed). This is usually where you should commit any changes that should be persisted beyond the current user session .
  • 7. There are several other lifecycle callback methods that you should use in order to provide a fluid user experience between activities and handle unexpected interuptions that cause your activity to be stopped and even destroyed. All of the lifecycle callback methods are discussed later, in the section about Managing the Activity Lifecycle. onResume() onStart() onStop() onDestroy() onPause() Other Methods
  • 8. Sample Code public class ExampleActivity extends Activity { Public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); // The activity is being created. } Protected void onStart(){ super.onstart(); // The activity is about to become visible. } Protected void onPause(){ super.onPause(); // Another activity is taking focus (this activity is about to be "paused"). } Protected void onResume(){ super.onPause(); // The activity has become visible (it is now "resumed"). } Protected void onstop(){ super.onPause(); // The activity is no longer visible (it is now "stopped") } Protected void onDestroy(){ super.onPause(); // The activity is about to be destroyed. } } This is super class For all classes
  • 9. Declaring the activity in the manifest You must declare your activity in the manifest file in order for it to be accessible to the system. To decalare your activity, open your manifest file and add an <activity> element as a child of the <application> element. For example: <manifest ... > <application ... > <activity android: name=".ExampleActivity" /> ... </application ... > ... </manifest >
  • 10. Using intent filters An <activity> element can also specify various intent filters—using the <intent-filter> element—in order to declare how other application components may activate it. • When you create a new application using the Android SDK tools, the stub activity that's created for you automatically includes an intent filter that declares the activity responds to the "main" action and should be placed in the "launcher" category. The intent filter looks like this:
  • 11. Using intent filters <activity android:name=".ExampleActivity" android:icon="@drawable/app_icon"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> The <action> element specifies that this is the "main" entry point to the application. The <category> element specifies that this activity should be listed in the system's application launcher (to allow users to launch this activity).
  • 12. Starting an Activity You can start another activity by calling startActivity(), passing it an Intent that describes the activity you want to start. An intent can also carry small amounts of data to be used by the activity that is started. For example : Intent intent = new Intent(this, Next. class); intent.putExtra(“key”, value); startActivity(intent); Which is going to be executed