Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Android application development fundamentals

632 views

Published on

Some concepts to understand the things that relate to basics of development on the Android Platform. The presentation explains the concept of formation of virtual machine for each android app. It also explains the main components like Activities, Services, Content Provider and Broadcast Receiver. The purpose of Intent is also explained. One can also find a brief on things that one can write in the Manifest file. The types of resources have also been explained. Finally one learns to know about the android metrics.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Android application development fundamentals

  1. 1. ANDROID Application Development Fundamentals 1 A Programme Under the Compumitra Series Copyright 2012-15 © Sunmitra Education Technologies Limited, India
  2. 2. 2 Outline • Basics of Applications • Principle of Least Privilege • Data Sharing • Application Component • Manifest File • Resources • Metrics
  3. 3. Basics of Android Applications 3
  4. 4. Basic Fundas • Programs are mainly written in Java. Can be written in other languages, but need to create DVM compatible code. • Entire Application Code, Data and Resources are compiled and created into one package that comes with an .apk suffix. • The .apk file is the file that is used to install applications onto the target system.
  5. 5. Application Working Concept 5 Linux VM1 VM2 VM3 VM4 App-1 App-2 App-3 App-4 App-4 UserID - A UserID - B UserID - C UserID - D We can arrange for two apps to share same VM and same User ID to share data Most apps will run in their own VM and a self generated UserID (unknown to app) Apps can make specific requests to get permission to access device data like contacts, SMS, SD card, Camera, Bluetooth. This permission is specifically granted at installation time.
  6. 6. Application Working • Each process is started only when required and shut-off when not in need, to recover memory for other application. • Each applications runs in its own Sandbox.
  7. 7. Principle of Least Privilege
  8. 8. Power Needs Security • Each process can use only the components needed. • It can not crossover to other memory area and read/write anything where other application is doing something. • This makes it highly secure and free of memory leaks.
  9. 9. Data Sharing Between Applications
  10. 10. Secure Things also need Sharing • When sharing between applications is required they share the same Linux user id. • Same user Id processes can also arrange to run in same process and share same virtual machine. • Application requests permission to access, contacts, SD card, SMS etc. • Permissions are granted by the end user the time of application installation.
  11. 11. Application Components
  12. 12. 4 Basic Types • Activities • Services • Content Providers • Broadcast Receivers
  13. 13. Activities • A single screen with a user interface. • Activity can be divided into multiple screen areas called fragments. • For an Email application – View Email List Activity – Compose Email Activity – View Settings Activity • Each activity is independent and can be started by other applications/activities. • Activities are implemented as a subclass of Activity.
  14. 14. Activity Life Cycle 14
  15. 15. Activitiy-Fragments • Conceptually fragments allow to define screen area that could be used as a reusable components by multiple activities. • A fragment is a sub-activity which has its own lifecycle of creation, use and destruction, but is paused or destroyed along with its parent activity.
  16. 16. Fragment Lifecycle 16
  17. 17. Services • Some thing that runs in background and doesn't have a user interface. • Ex. Playing music in background. • Ex. Watching whether a new email is coming. • It is implemented as a subclass of Service. • Services are also independent and can be started by different applications.
  18. 18. Content Provider • It manages a shared set of data. • In a file system, SQLite, SDCard, • Through this data query, data update is possible. • Permissions need to be set to use any content. • Implemented as subclass of ContentProvider.
  19. 19. Broadcast Receiver • Responds to system wide announcements • For e.g. – Battery low – Screen turned off – Picture captured • Application can also initiate broadcast – Some data has been downloaded. • Implemented as subclass of BroadcastReciever.
  20. 20. Components Activation • Components like Activities, services, broadcast are activated by using Intents. • Intents are asynchronous in nature. • The purpose of Intents is to bind application components together at runtime. • They act as messengers between them. • Created with an Intent object. • The component ContentProvider is activated by a request from
  21. 21. Activation Examples. • startActivity( ), startActivityForResult( ) • startService( ), bindService( ) • sendBroadcast( ) • query( )
  22. 22. Manifest
  23. 23. Manifest Purpose • It is to tell the system about existence of various components. • To tell about user permissions. • Declaration of API version requirement • Hardware/Software features required by the application. • Libraries the application needs to link. • Saved as AndroidManifest.xml
  24. 24. Sample <?xml version="1.0" encoding="utf-8"?> <manifest ... > <application android:icon="@drawable/app_icon.png" ... > <activity android:name="com.example.project.ExampleActivity" android:label="@string/example_label" ... > </activity> ... </application> </manifest>
  25. 25. Manifest Nodes - 1 • uses-permission requests a permission from user, that must be granted to operate it correctly. • permission permission to use a local resource or activity, as well as to allow • permission-tree declares a base name for a tree of permissions. •
  26. 26. Manifest Nodes - 2 • permission-group allows to group logically related permissions. • instrumentation required to handle instrument class • uses-sdk allows to set minimum, maximum and target SDK version required to run the app.
  27. 27. Manifest Nodes - 3 • uses-configuration allows to set configuration of uses like allowing keyboard, keyboard type, touch screen uses etc. • uses-features allow to set feature uses like for camera, bluetooth etc. • supports-screens allows to set things related to screen sizes and densities.
  28. 28. Manifest Nodes - 4 • compatible-screens allows to set compatibility of application with different screens. • supports-gl-texture allow to set the type of texture compression used for storing images.
  29. 29. Manifest Nodes - 5 • application this special node related to application configuration, further supports sub-nodes such as: – activity – activity-alias – service – receiver – provider – uses-library
  30. 30. Resources
  31. 31. Items separate from Source codes • Defined Strings and other variables. • Images, Icons etc. • Layout of activities. • Audio/Video files. • Menus, Styles, Colours etc.
  32. 32. Understanding Resources - 1 • Resources are carried as integral part of android apps (apk files). • Resources are static content which are fixed for typical apk file. • One can however dynamically select the which resource portion to use for a given action.. 32
  33. 33. Understanding Resources - 2 • The purpose of having external resources at development time is the maintainability of application code. • Resources are usually kept in /res/ folder of the typical android project. • Resource can contain the media files or XML based configuration files 33
  34. 34. Understanding Resources – 3 • Typically available Resources are – Animations resources (in res/anim or res/drawables) – Color State Lists (in res/color), used for control states likes, pressed, focused etc. – Image resources (in res/drawables) – Layouts (in res/layout) – Menu (in res/menu) – Values (in res/values/strings.xml, res/values/dimens.xml, res/values/styles.xml, res/values/colors.xml) – Raw Audio/Video files (in res/raw folder) 34
  35. 35. Understanding Resources – 4 • Preferred Bitmap Graphics used for Android is png format. Jpg is acceptable. Gif is supported but discouraged. • Many drawable folders for bitmap graphics are made available on the basis of android screen pixel density. – ldpi (Low density – 120dpi) – mdpi (Medium density – 160 dpi) – hdpi (High Density – 240 dpi) – xhdpi (extra high density – 320 dpi) – xxhdpi (double extra high density – 480 dpi) – xxxhdpi (triple extra high density – 640 dpi) 35
  36. 36. Metrics
  37. 37. Units used in android apps • dp or dip – Device independent pixels. Use it for element sizes (text box, button etc.) and gaps. Same size feel on different screens. 1px = 1 dp on mdpi (px = dp * (dpi/160) ) • sp or sip – Scale Independent pixels. Use it for fonts. Usually equal to dp, but it reacts to font size configurations. • ems – Size of width of m of given fonts. Allows to set relative unit for elements with respect to font sizes. 37
  38. 38. 38 Bibliography • http://en.wikipedia.org • http://developer.android.co m • http://play.google.com • http://source.android.com • http://www.youtube.com
  39. 39. 39 Thanks. Discussion Follows… • Keep visiting www.sunmitra.com for programme updates. • Please keep interacting using the email sunmitraeducation@gmail.com . • Please subscribe us when you get a facebook invitation from sunmitra.

×