SlideShare a Scribd company logo
1 of 27
Download to read offline
Android Application
Components
Application Fundamentals
Activities
• An activity is a class that is considered as an entry point for users that
represents a single screen.
• Each activity is independent of one another.
• Each process state – Call Back
• To implement an activity, extend the Activity class in your subclass:
public class MainActivity extends Activity {
//code
}
onCreate( )-This is the first callback that is fired when the system first creates
an activity. Android Studio itself calls this method in the java file
New Empty
Activity's Java File
onStart( )
• The system invokes this callback when the activity enters the Started
state. This method is called once the onCreate( ) callback has
finished.
• The onStart( ) call’s work is to makes the activity visible to the
user as the app prepares for the activity to come in the foreground
and start interacting with the user.
• This method is where the app initializes the code that maintains the
User Interface.
onResume( )
• When the activity enters the Resumed state, the system calls the
onResume( ) callback and the activity is now in the foreground.
• The Resumed state is where the activity can interact with the user.
• Any activity continues to stay in this state until focus is taken away
from the app by some other actions performed.
protected void onResume()
{
super.onResume();
}
onPause( )
• The onPause( ) method is called when the user is leaving the activity.
• It does not always indicate that the activity is being destroyed, but it tells that
the activity is now no longer in the foreground.
• Whenever a user leaves any activity it first enters into the Paused state and the
onPause( ) method is called, then it enters the Stopped state and the onStop( )
method is called.
• Running in background
• You can use the onPause( ) method to release the system resources if any in use
by your application, such as GPS or Camera as the activity is in the background
and the user no longer needs them.
Example
protected void onPause() {
super.onPause();
//When activity enters Paused state the onPause() method is called.
//Checking is the app is using camera.
if (camera != null) {
//If camera is in use, release the camera resource.
camera.release();
//Setting the camera variable to null.
camera = null;
}
}
onStop( )
• The activity is in Stopped state when it is no longer visible to the user
and the system invokes the onStop( ) callback. The activity can go
Stopped for various reasons, for example:
• If the user navigates to a new activity and that new activity completely covers
the screen.
• If the user minimizes the application and it is now in the background.
• When the activity is about to terminate, the system enters Stopped state,
invokes onStop( ) callback once the onPause( ) callback is finished.
onDestroy( )
• The system invokes the onDestroy( ) callback before the activity is
about to be destroyed. Following are the reasons for onDestroy to be
called:
• The activity is finished due to the user completely closing the activity or due
to the finish( ) method being called inside the activity.
• the system is temporarily destroying the activity due to a configuration
change such as device rotation or multi-window mode.
Services
• A service is a component that runs in the background to perform long-running
operations.
• A service does not provide a user interface.
• it acts as an invisible worker of our application. It keeps updating data sources and
activities.
• It also broadcasts intents and performs tasks when applications are not active.
• An example of service is we can surf the internet or use any other application while
listening to music.
• To execute services, extend the Services class in your sub-class:
public class MyService extends Services {
//code
}
Content Providers
• Content Provider is a component that allows applications to share
data among multiple applications.
• It hides the details of the database and can be used to read and write
private data of the application which is not shared.
• To implement this, extend ContentProvider in your subclass:
public class Provider_Name extendsContentProvider {
public void onCreate(){}
}
Broadcast Receiver
• Broadcast Receiver is a component that responds to broadcast messages
from another application or the same system.
• It can also deliver broadcasts to applications that are not running.
• For example – notify the user that the battery is low.
• To implement this, extend BroadcastReceiver to your receiver:
public class MyReccceiver extends BroadcastReceiver {
public void onReceive(context,intent)
{
//code
}
}
• Broadcast Receivers simply respond to broadcast messages from other
applications or from the system itself. These messages are sometime
called events or intents.
• let other applications know that some data has been downloaded to the
device and is available for them to use
Build an intent
• An Intent is an object that provides runtime binding between separate
components, such as two activities. The Intent represents an app’s intent to
do something.
• Intent intent = new Intent(First_activity.class , Second_activity.class);
• An intent is to perform an action on the screen. It is mostly used to start
activity, send broadcast receiver,start services and send message between
two activities
Steps
• Create the Activities
• Add the Activities to the app’s Manifest
• Create an Intent referencing the Activity class you want to switch to
• Call the startActivity(Intent) method to switch to the Activity
• Create a back button on the new Activity and call the finish()
method on an Activity when the back button is pressed
How to send data from one activity to second
activity
• For this, Intent will start and following methods will run:
•
putExtra() method is use for send the data, data in key value
pair key is variable name and value can be Int, String, Float etc.
• getStringExtra() method is for get the data(key) which is send by
above method. according the data type of value there are other
methods like getIntExtra(), getFloatExtra()
Android Activities.pdf

More Related Content

Similar to Android Activities.pdf

Anatomy of android application
Anatomy of android applicationAnatomy of android application
Anatomy of android applicationNikunj Dhameliya
 
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.pptxMugiiiReee
 
android activity
android activityandroid activity
android activityDeepa Rani
 
Android application development
Android application developmentAndroid application development
Android application developmentMd. Mujahid Islam
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2DHIRAJ PRAVIN
 
Lecture 3 getting active through activities
Lecture 3 getting active through activities Lecture 3 getting active through activities
Lecture 3 getting active through activities Ahsanul Karim
 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptbharatt7
 
04 activities and activity life cycle
04 activities and activity life cycle04 activities and activity life cycle
04 activities and activity life cycleSokngim Sa
 
Android activity
Android activityAndroid activity
Android activityKrazy Koder
 
Android activity
Android activityAndroid activity
Android activityKrazy Koder
 
App anatomy and life cycle
App anatomy and life cycleApp anatomy and life cycle
App anatomy and life cycleSV.CO
 
Android activity
Android activityAndroid activity
Android activityMohNage7
 
Android Training (Services)
Android Training (Services)Android Training (Services)
Android Training (Services)Khaled Anaqwa
 
02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)TECOS
 
Threads handlers and async task, widgets - day8
Threads   handlers and async task, widgets - day8Threads   handlers and async task, widgets - day8
Threads handlers and async task, widgets - day8Utkarsh Mankad
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Gabor Varadi
 

Similar to Android Activities.pdf (20)

Basics 4
Basics   4Basics   4
Basics 4
 
Anatomy of android application
Anatomy of android applicationAnatomy of android application
Anatomy of android application
 
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
 
android activity
android activityandroid activity
android activity
 
Android
AndroidAndroid
Android
 
Android application development
Android application developmentAndroid application development
Android application development
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2
 
Lecture 3 getting active through activities
Lecture 3 getting active through activities Lecture 3 getting active through activities
Lecture 3 getting active through activities
 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.ppt
 
Unit2
Unit2Unit2
Unit2
 
04 activities and activity life cycle
04 activities and activity life cycle04 activities and activity life cycle
04 activities and activity life cycle
 
Android activity
Android activityAndroid activity
Android activity
 
Android activity
Android activityAndroid activity
Android activity
 
App anatomy and life cycle
App anatomy and life cycleApp anatomy and life cycle
App anatomy and life cycle
 
Android activity
Android activityAndroid activity
Android activity
 
Android Training (Services)
Android Training (Services)Android Training (Services)
Android Training (Services)
 
fragments-activity.pptx
fragments-activity.pptxfragments-activity.pptx
fragments-activity.pptx
 
02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)
 
Threads handlers and async task, widgets - day8
Threads   handlers and async task, widgets - day8Threads   handlers and async task, widgets - day8
Threads handlers and async task, widgets - day8
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
 

Recently uploaded

main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 

Recently uploaded (20)

main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 

Android Activities.pdf

  • 2.
  • 3.
  • 4. Activities • An activity is a class that is considered as an entry point for users that represents a single screen. • Each activity is independent of one another. • Each process state – Call Back
  • 5. • To implement an activity, extend the Activity class in your subclass: public class MainActivity extends Activity { //code }
  • 6.
  • 7. onCreate( )-This is the first callback that is fired when the system first creates an activity. Android Studio itself calls this method in the java file New Empty Activity's Java File
  • 8. onStart( ) • The system invokes this callback when the activity enters the Started state. This method is called once the onCreate( ) callback has finished. • The onStart( ) call’s work is to makes the activity visible to the user as the app prepares for the activity to come in the foreground and start interacting with the user. • This method is where the app initializes the code that maintains the User Interface.
  • 9. onResume( ) • When the activity enters the Resumed state, the system calls the onResume( ) callback and the activity is now in the foreground. • The Resumed state is where the activity can interact with the user. • Any activity continues to stay in this state until focus is taken away from the app by some other actions performed. protected void onResume() { super.onResume(); }
  • 10. onPause( ) • The onPause( ) method is called when the user is leaving the activity. • It does not always indicate that the activity is being destroyed, but it tells that the activity is now no longer in the foreground. • Whenever a user leaves any activity it first enters into the Paused state and the onPause( ) method is called, then it enters the Stopped state and the onStop( ) method is called. • Running in background • You can use the onPause( ) method to release the system resources if any in use by your application, such as GPS or Camera as the activity is in the background and the user no longer needs them.
  • 11. Example protected void onPause() { super.onPause(); //When activity enters Paused state the onPause() method is called. //Checking is the app is using camera. if (camera != null) { //If camera is in use, release the camera resource. camera.release(); //Setting the camera variable to null. camera = null; } }
  • 12. onStop( ) • The activity is in Stopped state when it is no longer visible to the user and the system invokes the onStop( ) callback. The activity can go Stopped for various reasons, for example: • If the user navigates to a new activity and that new activity completely covers the screen. • If the user minimizes the application and it is now in the background. • When the activity is about to terminate, the system enters Stopped state, invokes onStop( ) callback once the onPause( ) callback is finished.
  • 13. onDestroy( ) • The system invokes the onDestroy( ) callback before the activity is about to be destroyed. Following are the reasons for onDestroy to be called: • The activity is finished due to the user completely closing the activity or due to the finish( ) method being called inside the activity. • the system is temporarily destroying the activity due to a configuration change such as device rotation or multi-window mode.
  • 14. Services • A service is a component that runs in the background to perform long-running operations. • A service does not provide a user interface. • it acts as an invisible worker of our application. It keeps updating data sources and activities. • It also broadcasts intents and performs tasks when applications are not active. • An example of service is we can surf the internet or use any other application while listening to music. • To execute services, extend the Services class in your sub-class: public class MyService extends Services { //code }
  • 15.
  • 16. Content Providers • Content Provider is a component that allows applications to share data among multiple applications. • It hides the details of the database and can be used to read and write private data of the application which is not shared. • To implement this, extend ContentProvider in your subclass: public class Provider_Name extendsContentProvider { public void onCreate(){} }
  • 17.
  • 18.
  • 19. Broadcast Receiver • Broadcast Receiver is a component that responds to broadcast messages from another application or the same system. • It can also deliver broadcasts to applications that are not running. • For example – notify the user that the battery is low. • To implement this, extend BroadcastReceiver to your receiver: public class MyReccceiver extends BroadcastReceiver { public void onReceive(context,intent) { //code } }
  • 20. • Broadcast Receivers simply respond to broadcast messages from other applications or from the system itself. These messages are sometime called events or intents. • let other applications know that some data has been downloaded to the device and is available for them to use
  • 21.
  • 22.
  • 23. Build an intent • An Intent is an object that provides runtime binding between separate components, such as two activities. The Intent represents an app’s intent to do something. • Intent intent = new Intent(First_activity.class , Second_activity.class); • An intent is to perform an action on the screen. It is mostly used to start activity, send broadcast receiver,start services and send message between two activities
  • 24.
  • 25. Steps • Create the Activities • Add the Activities to the app’s Manifest • Create an Intent referencing the Activity class you want to switch to • Call the startActivity(Intent) method to switch to the Activity • Create a back button on the new Activity and call the finish() method on an Activity when the back button is pressed
  • 26. How to send data from one activity to second activity • For this, Intent will start and following methods will run: • putExtra() method is use for send the data, data in key value pair key is variable name and value can be Int, String, Float etc. • getStringExtra() method is for get the data(key) which is send by above method. according the data type of value there are other methods like getIntExtra(), getFloatExtra()