SlideShare a Scribd company logo
1 of 19
1
Hello Android

1. Create a new project by – file -> New Project -> Android Project.
2. Enter the details -
          Project Name – HelloWorld
          Build Target – Android 2.2 (API 8)
          Application Name – Hello Android
          Package name – cdac.android.helloworld
          Activity name – HelloWorldActivity
3. Click o finish, and wait for the project to be created.
4. The build your project.
5. Then click o the play icon In the taskbar on the top, or right click on the project
   folder In the workspace, and then select – android application
6. Select the AVD corresponding to the build target, and then wait for the
   emulator to load




                                                                                         2
Select AVD


New Project



                           3
Understanding Hello world
Android Project file structure
                                 Project Name

                                 1.Src
                                 2.Gen
                                 3.Android version Libraries
                                 4.Assets
                                 5.Res
                                           - drawable-hdpi
                                           -drawable-ldpi
                                           -drawable-mdpi
                                           -layout
                                           -values
                                 6.AndroidManifest.xml
                                 7.Default.properties




                                                               4
Brief Description about the Folders

Src an assets folder

This src folder, contains the actual source code

Res and assets folder

The Resource aka res folder, contains all the resource files which are divided into
generally 5 folders

          a. drawable – hdpi
          b drawable – ldpi
          c. drawable – mdpi
          d. layout
          e. values

Apart from all other files are added to the assets folder like java projects,



                                                                                      5
The gen folder

The gen folder contains the file R.java.
This file is auto generated
R.Java contains set of unique
precompiled IDs assigned to every
resource in the res folder.

The default.properties file

This file generally contains the
information regarding the version of
Android used to make the application.
But, in order to specify or change the
build environment or parameters we’ll
modify this file



                                           6
AndroidManifest. xml

The manifest lets you define the structure and metadata of your application, its
components, and its requirements.

Breaking down

1. Activity tag – To describe any new activity in the application

2. Application, intent-filter tag

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".DatePickerActivity"
          android:label="@string/app_name">
       <intent-filter>
         <action android:name="android.intent.action.MAIN" />
         <category android:name="android.intent.category.LAUNCHER" />
       </intent-filter>
    </activity>
  </application>

                                                                                   7
3. Android Permissions (uses-application tag)

   The Android permissions are the set of hardware/software permissions to be
   taken by the current application.

   <uses-permission android:name="android.permission.INTERNET" />




                                                                                8
Android 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.

The very first step in developing an
Android application is making a
Activity
Your application must have at least
one Activity.




                                       9
Importance of Activity

An activity is a single, focused thing that the user can do. Almost all activities
interact with the user, so the Activity class takes care of creating a window for you
in which you can place your UI .

While activities are often presented to the user as full-screen windows, they can
also be used in other ways: as floating windows or embedded inside of another
activity (using ActivityGroup).




                                                                                        10
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 the most important
callback methods are:

onCreate()
The system calls this when creating your activity.

Most importantly, this is where you must call setContentView() to define the
layout for the activity's user interface.

onPause()
This is usually where we should commit any changes that should be persisted
beyond the current user session (because the user might not come back).




                                                                                11
Dissection of an Activity
Some of the important overridden methods in the Activity Class
1.onStart();
2.onRestart();
3.onResume();
4.onPause();
5.onStop();
6.onDestroy();
7.void finish();
8.void finishActivity(int requestCode);
9.setContentView(int layoutResID);
10.void setTitle(CharSequence title)
11.startActivity(Intent intent)
12.setIntent(Intent newIntent)
13.View findViewById(int id) ;
14.PendingIntent createPendingResult(int requestCode, Intent data, int flags);
15.Boolean onKeyEvent(KeyEvent event);
16.boolean onTouchEvent(MotionEvent ev);
17.boolean onTrackballEvent(MotionEvent ev);

                                                                                 12
1. LayoutInflater getLayoutInflater()
2. WindowManager getWindowManager()
3. Window getWindow()
4. Dialog onCreateDialog(int id)
5. boolean onCreatePanelMenu(int featureId, Menu menu)
6. View onCreatePanelView(int featureId)
7. Boolean onCreateThumbnail(Bitmap outBitmap, Canvas canvas)
8. View onCreateView(String name, Context context, AttributeSet attrs)
9. boolean onMenuItemSelected(int featureId, MenuItem item)
10. startSearch(String initialQuery, boolean selectInitialQuery,Bundle appSearchData,
    boolean globalSearch)
11. startIntentSender(IntentSender intent, Intent fillInIntent,int flagsMask, int
    flagsValues, int extraFlags)
12. boolean startActivityIfNeeded(Intent intent, int requestCode)




                                                                                   13
Activity Life Cycle




                      14
Summary of Activity Life cycle




                                 15
Android Service

A Service is an application component that can perform long-running operations in
the background and does not provide a user interface.

Additionally, a component can bind to a service to interact with it and even perform
interprocess communication (IPC).




                                                                                       16
Broadcast Receivers

A broadcast receiver is a class which extends "BroadcastReceiver" and which is
registered as a receiver in an Android Application via the AndroidManifest.xml (or
via code). This class will be able to receive intents via the sendBroadcast() method.

Broadcast receiver is a component that responds to system-wide broadcast
announcements




                                                                                        17
References

1. http://developer.android.com/reference/android/app/Activity.html
2. http://developer.android.com/reference/android/app/Service.html
3. http://developer.android.com/reference/android/content/BroadcastReceiver.html




                                                                          18
19

More Related Content

Similar to Android activity, service, and broadcast recievers

Android application development
Android application developmentAndroid application development
Android application developmentslidesuren
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recieversUtkarsh Mankad
 
Android developer interview questions with answers pdf
Android developer interview questions with answers pdfAndroid developer interview questions with answers pdf
Android developer interview questions with answers pdfazlist247
 
Native Android Development Practices
Native Android Development PracticesNative Android Development Practices
Native Android Development PracticesRoy Clarkson
 
Day: 2 Environment Setup for Android Application Development
Day: 2 Environment Setup for Android Application DevelopmentDay: 2 Environment Setup for Android Application Development
Day: 2 Environment Setup for Android Application DevelopmentAhsanul Karim
 
Android studio
Android studioAndroid studio
Android studioAndri Yabu
 
Android application development workshop day1
Android application development workshop   day1Android application development workshop   day1
Android application development workshop day1Borhan Otour
 
Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Ahsanul Karim
 
Android interview questions and answers
Android interview questions and answersAndroid interview questions and answers
Android interview questions and answerskavinilavuG
 
Introduction to Android Development Part 1
Introduction to Android Development Part 1Introduction to Android Development Part 1
Introduction to Android Development Part 1Kainda Kiniel Daka
 
Android Development in a Nutshell
Android Development in a NutshellAndroid Development in a Nutshell
Android Development in a NutshellAleix Solé
 
Android Development project
Android Development projectAndroid Development project
Android Development projectMinhaj Kazi
 
Google android white paper
Google android white paperGoogle android white paper
Google android white paperSravan Reddy
 

Similar to Android activity, service, and broadcast recievers (20)

Android application development
Android application developmentAndroid application development
Android application development
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
 
Android developer interview questions with answers pdf
Android developer interview questions with answers pdfAndroid developer interview questions with answers pdf
Android developer interview questions with answers pdf
 
Native Android Development Practices
Native Android Development PracticesNative Android Development Practices
Native Android Development Practices
 
Day: 2 Environment Setup for Android Application Development
Day: 2 Environment Setup for Android Application DevelopmentDay: 2 Environment Setup for Android Application Development
Day: 2 Environment Setup for Android Application Development
 
Android Basic- CMC
Android Basic- CMCAndroid Basic- CMC
Android Basic- CMC
 
Android studio
Android studioAndroid studio
Android studio
 
Android application development workshop day1
Android application development workshop   day1Android application development workshop   day1
Android application development workshop day1
 
Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3
 
Android interview questions and answers
Android interview questions and answersAndroid interview questions and answers
Android interview questions and answers
 
Introduction to Android Development Part 1
Introduction to Android Development Part 1Introduction to Android Development Part 1
Introduction to Android Development Part 1
 
Android dev o_auth
Android dev o_authAndroid dev o_auth
Android dev o_auth
 
Android session-1-sajib
Android session-1-sajibAndroid session-1-sajib
Android session-1-sajib
 
Unit I- ANDROID OVERVIEW.ppt
Unit I- ANDROID OVERVIEW.pptUnit I- ANDROID OVERVIEW.ppt
Unit I- ANDROID OVERVIEW.ppt
 
Android basics
Android basicsAndroid basics
Android basics
 
Android cours
Android coursAndroid cours
Android cours
 
Android Development in a Nutshell
Android Development in a NutshellAndroid Development in a Nutshell
Android Development in a Nutshell
 
ANDROID PPT 1.pdf
ANDROID PPT 1.pdfANDROID PPT 1.pdf
ANDROID PPT 1.pdf
 
Android Development project
Android Development projectAndroid Development project
Android Development project
 
Google android white paper
Google android white paperGoogle android white paper
Google android white paper
 

Recently uploaded

ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 

Recently uploaded (20)

ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 

Android activity, service, and broadcast recievers

  • 1. 1
  • 2. Hello Android 1. Create a new project by – file -> New Project -> Android Project. 2. Enter the details - Project Name – HelloWorld Build Target – Android 2.2 (API 8) Application Name – Hello Android Package name – cdac.android.helloworld Activity name – HelloWorldActivity 3. Click o finish, and wait for the project to be created. 4. The build your project. 5. Then click o the play icon In the taskbar on the top, or right click on the project folder In the workspace, and then select – android application 6. Select the AVD corresponding to the build target, and then wait for the emulator to load 2
  • 4. Understanding Hello world Android Project file structure Project Name 1.Src 2.Gen 3.Android version Libraries 4.Assets 5.Res - drawable-hdpi -drawable-ldpi -drawable-mdpi -layout -values 6.AndroidManifest.xml 7.Default.properties 4
  • 5. Brief Description about the Folders Src an assets folder This src folder, contains the actual source code Res and assets folder The Resource aka res folder, contains all the resource files which are divided into generally 5 folders a. drawable – hdpi b drawable – ldpi c. drawable – mdpi d. layout e. values Apart from all other files are added to the assets folder like java projects, 5
  • 6. The gen folder The gen folder contains the file R.java. This file is auto generated R.Java contains set of unique precompiled IDs assigned to every resource in the res folder. The default.properties file This file generally contains the information regarding the version of Android used to make the application. But, in order to specify or change the build environment or parameters we’ll modify this file 6
  • 7. AndroidManifest. xml The manifest lets you define the structure and metadata of your application, its components, and its requirements. Breaking down 1. Activity tag – To describe any new activity in the application 2. Application, intent-filter tag <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".DatePickerActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> 7
  • 8. 3. Android Permissions (uses-application tag) The Android permissions are the set of hardware/software permissions to be taken by the current application. <uses-permission android:name="android.permission.INTERNET" /> 8
  • 9. Android 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. The very first step in developing an Android application is making a Activity Your application must have at least one Activity. 9
  • 10. Importance of Activity An activity is a single, focused thing that the user can do. Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI . While activities are often presented to the user as full-screen windows, they can also be used in other ways: as floating windows or embedded inside of another activity (using ActivityGroup). 10
  • 11. 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 the most important callback methods are: onCreate() The system calls this when creating your activity. Most importantly, this is where you must call setContentView() to define the layout for the activity's user interface. onPause() This is usually where we should commit any changes that should be persisted beyond the current user session (because the user might not come back). 11
  • 12. Dissection of an Activity Some of the important overridden methods in the Activity Class 1.onStart(); 2.onRestart(); 3.onResume(); 4.onPause(); 5.onStop(); 6.onDestroy(); 7.void finish(); 8.void finishActivity(int requestCode); 9.setContentView(int layoutResID); 10.void setTitle(CharSequence title) 11.startActivity(Intent intent) 12.setIntent(Intent newIntent) 13.View findViewById(int id) ; 14.PendingIntent createPendingResult(int requestCode, Intent data, int flags); 15.Boolean onKeyEvent(KeyEvent event); 16.boolean onTouchEvent(MotionEvent ev); 17.boolean onTrackballEvent(MotionEvent ev); 12
  • 13. 1. LayoutInflater getLayoutInflater() 2. WindowManager getWindowManager() 3. Window getWindow() 4. Dialog onCreateDialog(int id) 5. boolean onCreatePanelMenu(int featureId, Menu menu) 6. View onCreatePanelView(int featureId) 7. Boolean onCreateThumbnail(Bitmap outBitmap, Canvas canvas) 8. View onCreateView(String name, Context context, AttributeSet attrs) 9. boolean onMenuItemSelected(int featureId, MenuItem item) 10. startSearch(String initialQuery, boolean selectInitialQuery,Bundle appSearchData, boolean globalSearch) 11. startIntentSender(IntentSender intent, Intent fillInIntent,int flagsMask, int flagsValues, int extraFlags) 12. boolean startActivityIfNeeded(Intent intent, int requestCode) 13
  • 15. Summary of Activity Life cycle 15
  • 16. Android Service A Service is an application component that can perform long-running operations in the background and does not provide a user interface. Additionally, a component can bind to a service to interact with it and even perform interprocess communication (IPC). 16
  • 17. Broadcast Receivers A broadcast receiver is a class which extends "BroadcastReceiver" and which is registered as a receiver in an Android Application via the AndroidManifest.xml (or via code). This class will be able to receive intents via the sendBroadcast() method. Broadcast receiver is a component that responds to system-wide broadcast announcements 17
  • 19. 19