1
Hello Android1. Create a new project by – file -> New Project -> Android Project.2. Enter the details -          Project N...
Select AVDNew Project                           3
Understanding Hello worldAndroid Project file structure                                 Project Name                      ...
Brief Description about the FoldersSrc an assets folderThis src folder, contains the actual source codeRes and assets fold...
The gen folderThe gen folder contains the file R.java.This file is auto generatedR.Java contains set of uniqueprecompiled ...
AndroidManifest. xmlThe manifest lets you define the structure and metadata of your application, itscomponents, and its re...
3. Android Permissions (uses-application tag)   The Android permissions are the set of hardware/software permissions to be...
Android ActivityAn Activity is an applicationcomponent that provides a screenwith which users can interact inorder to do s...
Importance of ActivityAn activity is a single, focused thing that the user can do. Almost all activitiesinteract with the ...
Creating an ActivityTo create an activity, you must create a subclass of Activity (or an existingsubclass of it). In your ...
Dissection of an ActivitySome of the important overridden methods in the Activity Class1.onStart();2.onRestart();3.onResum...
1. LayoutInflater getLayoutInflater()2. WindowManager getWindowManager()3. Window getWindow()4. Dialog onCreateDialog(int ...
Activity Life Cycle                      14
Summary of Activity Life cycle                                 15
Android ServiceA Service is an application component that can perform long-running operations inthe background and does no...
Broadcast ReceiversA broadcast receiver is a class which extends "BroadcastReceiver" and which isregistered as a receiver ...
References1. http://developer.android.com/reference/android/app/Activity.html2. http://developer.android.com/reference/and...
19
Upcoming SlideShare
Loading in …5
×

Android activity, service, and broadcast recievers

577 views
451 views

Published on

android

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
577
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Android activity, service, and broadcast recievers

  1. 1. 1
  2. 2. Hello Android1. 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 – HelloWorldActivity3. 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 application6. Select the AVD corresponding to the build target, and then wait for the emulator to load 2
  3. 3. Select AVDNew Project 3
  4. 4. Understanding Hello worldAndroid 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. 5. Brief Description about the FoldersSrc an assets folderThis src folder, contains the actual source codeRes and assets folderThe Resource aka res folder, contains all the resource files which are divided intogenerally 5 folders a. drawable – hdpi b drawable – ldpi c. drawable – mdpi d. layout e. valuesApart from all other files are added to the assets folder like java projects, 5
  6. 6. The gen folderThe gen folder contains the file R.java.This file is auto generatedR.Java contains set of uniqueprecompiled IDs assigned to everyresource in the res folder.The default.properties fileThis file generally contains theinformation regarding the version ofAndroid used to make the application.But, in order to specify or change thebuild environment or parameters we’llmodify this file 6
  7. 7. AndroidManifest. xmlThe manifest lets you define the structure and metadata of your application, itscomponents, and its requirements.Breaking down1. Activity tag – To describe any new activity in the application2. 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. 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. 9. Android ActivityAn Activity is an applicationcomponent that provides a screenwith which users can interact inorder to do something, such as dialthe phone, take a photo, send anemail, or view a map.The very first step in developing anAndroid application is making aActivityYour application must have at leastone Activity. 9
  10. 10. Importance of ActivityAn activity is a single, focused thing that the user can do. Almost all activitiesinteract with the user, so the Activity class takes care of creating a window for youin which you can place your UI .While activities are often presented to the user as full-screen windows, they canalso be used in other ways: as floating windows or embedded inside of anotheractivity (using ActivityGroup). 10
  11. 11. Creating an ActivityTo create an activity, you must create a subclass of Activity (or an existingsubclass of it). In your subclass, you need to implement the most importantcallback methods are:onCreate()The system calls this when creating your activity.Most importantly, this is where you must call setContentView() to define thelayout for the activitys user interface.onPause()This is usually where we should commit any changes that should be persistedbeyond the current user session (because the user might not come back). 11
  12. 12. Dissection of an ActivitySome of the important overridden methods in the Activity Class1.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. 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
  14. 14. Activity Life Cycle 14
  15. 15. Summary of Activity Life cycle 15
  16. 16. Android ServiceA Service is an application component that can perform long-running operations inthe background and does not provide a user interface.Additionally, a component can bind to a service to interact with it and even performinterprocess communication (IPC). 16
  17. 17. Broadcast ReceiversA broadcast receiver is a class which extends "BroadcastReceiver" and which isregistered as a receiver in an Android Application via the AndroidManifest.xml (orvia code). This class will be able to receive intents via the sendBroadcast() method.Broadcast receiver is a component that responds to system-wide broadcastannouncements 17
  18. 18. References1. http://developer.android.com/reference/android/app/Activity.html2. http://developer.android.com/reference/android/app/Service.html3. http://developer.android.com/reference/android/content/BroadcastReceiver.html 18
  19. 19. 19

×