SlideShare a Scribd company logo
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

What's hot

Android activities & views
Android activities & viewsAndroid activities & views
Android activities & views
ma-polimi
 
Android Widget
Android WidgetAndroid Widget
Android Widget
ELLURU Kalyan
 
Android UI
Android UIAndroid UI
Android UI
nationalmobileapps
 
Android | Android Activity Launch Modes and Tasks | Gonçalo Silva
Android | Android Activity Launch Modes and Tasks | Gonçalo SilvaAndroid | Android Activity Launch Modes and Tasks | Gonçalo Silva
Android | Android Activity Launch Modes and Tasks | Gonçalo Silva
JAX London
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
Elizabeth alexander
 
Fragment
Fragment Fragment
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestate
Osahon Gino Ediagbonya
 
Android Components
Android ComponentsAndroid Components
Android Components
Aatul Palandurkar
 
SQLITE Android
SQLITE AndroidSQLITE Android
SQLITE Android
Sourabh Sahu
 
SQLite database in android
SQLite database in androidSQLite database in android
SQLite database in android
Gourav Kumar Saini
 
Android notification
Android notificationAndroid notification
Android notificationKrazy Koder
 
Activity lifecycle
Activity lifecycleActivity lifecycle
Activity lifecycle
Rehan Choudhary
 
Android: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast ReceiversAndroid: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast Receivers
CodeAndroid
 
Android Intent.pptx
Android Intent.pptxAndroid Intent.pptx
Android Intent.pptx
vishal choudhary
 
Android terminologies
Android terminologiesAndroid terminologies
Android terminologies
jerry vasoya
 
Android User Interface
Android User InterfaceAndroid User Interface
Android User Interface
Shakib Hasan Sumon
 

What's hot (20)

Android activities & views
Android activities & viewsAndroid activities & views
Android activities & views
 
Android Widget
Android WidgetAndroid Widget
Android Widget
 
Android UI
Android UIAndroid UI
Android UI
 
Android | Android Activity Launch Modes and Tasks | Gonçalo Silva
Android | Android Activity Launch Modes and Tasks | Gonçalo SilvaAndroid | Android Activity Launch Modes and Tasks | Gonçalo Silva
Android | Android Activity Launch Modes and Tasks | Gonçalo Silva
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
 
Fragment
Fragment Fragment
Fragment
 
Android intents
Android intentsAndroid intents
Android intents
 
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestate
 
Android Components
Android ComponentsAndroid Components
Android Components
 
SQLITE Android
SQLITE AndroidSQLITE Android
SQLITE Android
 
SQLite database in android
SQLite database in androidSQLite database in android
SQLite database in android
 
Android notification
Android notificationAndroid notification
Android notification
 
AndroidManifest
AndroidManifestAndroidManifest
AndroidManifest
 
Activity lifecycle
Activity lifecycleActivity lifecycle
Activity lifecycle
 
Android: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast ReceiversAndroid: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast Receivers
 
Android Intent.pptx
Android Intent.pptxAndroid Intent.pptx
Android Intent.pptx
 
Android terminologies
Android terminologiesAndroid terminologies
Android terminologies
 
Android Location and Maps
Android Location and MapsAndroid Location and Maps
Android Location and Maps
 
Android User Interface
Android User InterfaceAndroid User Interface
Android User Interface
 
Android intent
Android intentAndroid intent
Android intent
 

Similar to android activity

Unit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptxUnit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptx
ShantanuDharekar
 
Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3
Dr. Ramkumar Lakshminarayanan
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2DHIRAJ PRAVIN
 
Android development session 2 - intent and activity
Android development   session 2 - intent and activityAndroid development   session 2 - intent and activity
Android development session 2 - intent and activity
Farabi Technology Middle East
 
Activity
ActivityActivity
Activity
NikithaNag
 
Activity
ActivityActivity
Activity
roopa_slide
 
Activity
ActivityActivity
Activity
NikithaNag
 
Activity
ActivityActivity
Activity
roopa_slide
 
android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last sem
aswinbiju1652
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
MugiiiReee
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - Android
Wingston
 
Android activity
Android activityAndroid activity
Android activityKrazy Koder
 
Android Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdf
ssusere71a07
 
Mad textbook 63-116
Mad textbook 63-116Mad textbook 63-116
Mad textbook 63-116
PrathishGM
 
Android Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesAndroid Application Components with Implementation & Examples
Android Application Components with Implementation & Examples
Chandrakant Divate
 
Android lifecycle
Android lifecycleAndroid lifecycle
Android lifecycle
Kumar
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
Monir Zzaman
 
Unit2
Unit2Unit2
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
PERKYTORIALS
 

Similar to android activity (20)

Unit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptxUnit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptx
 
Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2
 
Android development session 2 - intent and activity
Android development   session 2 - intent and activityAndroid development   session 2 - intent and activity
Android development session 2 - intent and activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last sem
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - Android
 
Android activity
Android activityAndroid activity
Android activity
 
Android Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdf
 
Mad textbook 63-116
Mad textbook 63-116Mad textbook 63-116
Mad textbook 63-116
 
Android Basic Components
Android Basic ComponentsAndroid Basic Components
Android Basic Components
 
Android Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesAndroid Application Components with Implementation & Examples
Android Application Components with Implementation & Examples
 
Android lifecycle
Android lifecycleAndroid lifecycle
Android lifecycle
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
Unit2
Unit2Unit2
Unit2
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
 

More from Deepa Rani

Speed controller of dc motor
Speed controller of dc motorSpeed controller of dc motor
Speed controller of dc motorDeepa Rani
 
Foot step power generator
Foot step power generatorFoot step power generator
Foot step power generatorDeepa Rani
 
Crime investigation system
Crime investigation systemCrime investigation system
Crime investigation systemDeepa Rani
 
android content providers
android content providersandroid content providers
android content providersDeepa Rani
 
android sqlite
android sqliteandroid sqlite
android sqliteDeepa Rani
 
android dilaogs
android dilaogsandroid dilaogs
android dilaogsDeepa Rani
 
android layouts
android layoutsandroid layouts
android layoutsDeepa Rani
 
android architecture,life cycle,sdk,execution process
android architecture,life cycle,sdk,execution processandroid architecture,life cycle,sdk,execution process
android architecture,life cycle,sdk,execution processDeepa Rani
 
Android the first app - hello world - copy
Android   the first app - hello world - copyAndroid   the first app - hello world - copy
Android the first app - hello world - copyDeepa Rani
 
Android styles and themes
Android   styles and themesAndroid   styles and themes
Android styles and themesDeepa Rani
 
Review of basic data structures
Review of basic data structuresReview of basic data structures
Review of basic data structuresDeepa Rani
 
Fabric innovation
Fabric innovationFabric innovation
Fabric innovationDeepa Rani
 
Typical problem
Typical problemTypical problem
Typical problemDeepa Rani
 
straight line
straight line straight line
straight line Deepa Rani
 
Section of solids
Section of solidsSection of solids
Section of solidsDeepa Rani
 

More from Deepa Rani (20)

Speed controller of dc motor
Speed controller of dc motorSpeed controller of dc motor
Speed controller of dc motor
 
Foot step power generator
Foot step power generatorFoot step power generator
Foot step power generator
 
Crime investigation system
Crime investigation systemCrime investigation system
Crime investigation system
 
android content providers
android content providersandroid content providers
android content providers
 
android sqlite
android sqliteandroid sqlite
android sqlite
 
android menus
android menusandroid menus
android menus
 
android dilaogs
android dilaogsandroid dilaogs
android dilaogs
 
android layouts
android layoutsandroid layouts
android layouts
 
android architecture,life cycle,sdk,execution process
android architecture,life cycle,sdk,execution processandroid architecture,life cycle,sdk,execution process
android architecture,life cycle,sdk,execution process
 
Android the first app - hello world - copy
Android   the first app - hello world - copyAndroid   the first app - hello world - copy
Android the first app - hello world - copy
 
Android styles and themes
Android   styles and themesAndroid   styles and themes
Android styles and themes
 
Review of basic data structures
Review of basic data structuresReview of basic data structures
Review of basic data structures
 
Blue Brain
Blue BrainBlue Brain
Blue Brain
 
Tcp
TcpTcp
Tcp
 
Dc machiness
Dc machinessDc machiness
Dc machiness
 
Maddy android
Maddy androidMaddy android
Maddy android
 
Fabric innovation
Fabric innovationFabric innovation
Fabric innovation
 
Typical problem
Typical problemTypical problem
Typical problem
 
straight line
straight line straight line
straight line
 
Section of solids
Section of solidsSection of solids
Section of solids
 

Recently uploaded

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 

Recently uploaded (20)

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 

android activity

  • 1.
  • 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