Android application structure


Published on

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Android application structure

  1. 1. Alexey Ustenko programmer @ustav
  2. 2. Application Structure
  3. 3. <ul><li>Application Components </li></ul><ul><li>Application components are the essential building blocks of an Android application. </li></ul><ul><li>Each component is a different point through which the system can enter your application. </li></ul><ul><li>Here are the four types of application components: </li></ul><ul><li>Activities </li></ul><ul><li>Services </li></ul><ul><li>Content providers </li></ul><ul><li>Broadcast receivers </li></ul>
  4. 4. Activities An activity represents a single screen with a user interface. Services A service is a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface. Content providers A content provider manages a shared set of application data. You can store the data in the file system, an SQLite database, on the web, or any other persistent storage location your application can access. Through the content provider, other applications can query or even modify the data (if the content provider allows it). Broadcast receivers A broadcast receiver is a component that responds to system-wide broadcast announcements. Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured. Applications can also initiate broadcasts.
  5. 5. Activating Components A unique aspect of the Android system design is that any application can start another application’s component. Three of the four component types—activities, services, and broadcast receivers—are activated by an asynchronous message called an  intent .
  6. 6. <ul><li>The Manifest File </li></ul><ul><li>Your application must declare all its components in this file, which must be at the root of the application project directory. </li></ul><ul><li>The manifest does a number of things in addition to declaring the application's components, such as: </li></ul><ul><li>Identify any user permissions the application requires </li></ul><ul><li>Declare the minimum API Level required by the application </li></ul><ul><li>Declare hardware and software features used or required by the application </li></ul><ul><li>API libraries the application needs to be linked against </li></ul><ul><li>And more </li></ul>
  7. 7. Declaring components The primary task of the manifest is to inform the system about the application's components. For example, a manifest file can declare an activity as follows: <? xml version = &quot;1.0&quot; encoding = &quot;utf-8&quot; ?> < manifest xmlns:android = &quot;; package = &quot;com.test.appstructure&quot; android:versionCode = &quot;1&quot; android:versionName = &quot;1.0&quot; > < uses-sdk android:minSdkVersion = &quot;4&quot; /> < application android:icon = &quot;@drawable/icon&quot; android:label = &quot;@string/app_name&quot; > < activity android:name = &quot;.MainActivity&quot; android:label = &quot;@string/app_name&quot; > < intent-filter > < action android:name = &quot;android.intent.action.MAIN&quot; /> < category android:name = &quot;android.intent.category.LAUNCHER&quot; /> </ intent-filter > </ activity > </ application > </ manifest > Activities, services, and content providers that you include in your source but do not declare in the manifest are not visible to the system and, consequently, can never run.
  8. 8. Application Resources For every resource that you include in your Android project, the SDK build tools define a unique integer ID , which you can use to reference the resource from your application code or from other resources defined in XML. One of the most important aspects of providing resources separate from your source code is the ability for you to provide alternative resources for different device configurations.
  9. 9. Android Projects An application project is the main type of project and the contents are eventually built into an .apk file that you install on a device. Test Projects These projects contain code to test your application projects and are built into applications that run on a device. Library Projects These projects contain shareable Android source code and resources that you can reference in Android projects. Library projects cannot be installed onto a device, however, they are pulled into the .apk file at build time.
  10. 10. Contains your stub Activity file, which is stored at src/your/package/ All other source code files (such as .java or .aidl files) go here as well.
  11. 11. Contains the Java files generated by ADT, such as your file and interfaces created from AIDL files.
  12. 12. You can use it to store raw asset files. Files that you save here are compiled into an .apk file as-is, and the original filename is preserved.
  13. 13. Contains private libraries.
  14. 14. Contains application resources, such as drawable files, layout files, and string values
  15. 15. For XML files that are compiled into animation objects
  16. 16. For XML files that describe colors
  17. 17. For bitmap files (PNG, JPEG, or GIF), 9-Patch image files, and XML files that describe Drawable shapes or a Drawable objects that contain multiple states (normal, pressed, or focused)
  18. 18. XML files that are compiled into screen layouts (or part of a screen)
  19. 19. For XML files that define application menus
  20. 20. For arbitrary raw asset files. Saving asset files here instead of in the assets/ directory only differs in the way that you access them. These files are processed by aapt and must be referenced from the application using a resource identifier in the R class. For example, this is a good place for media, such as MP3 or Ogg files.
  21. 21. For XML files that are compiled into many kinds of resource. Unlike other resources in the res/ directory, resources written to XML files in this folder are not referenced by the file name. Instead, the XML element type controls how the resources is defined within them are placed into the R class.
  22. 22. For miscellaneous XML files that configure application components. For example, an XML file that defines a PreferenceScreen, AppWidgetProviderInfo, or Searchability Metadata.
  23. 23. The control file that describes the nature of the application and each of its components. For instance, it describes: certain qualities about the activities, services, intent receivers, and content providers; what permissions are requested; what external libraries are needed; what device features are required, what API Levels are supported or required; and others.
  24. 24. This file contains project settings, such as the build target. This files is integral to the project, as such, it should be maintained in a Source Revision Control system. Do not edit the file manually.
  25. 25. This file defines how ProGuard optimizes and obfuscates your code
  26. 26. Security The Android operating system is a multi-user Linux system in which each application is a different user. Each process has its own virtual machine (VM), so an application's code runs in isolation from other applications. An application can request permission to access device data such as the user's contacts, SMS messages, the mountable storage (SD card), camera, Bluetooth, and more. All application permissions must be granted by the user at install time.
  27. 27. /Android/data/<package_name>/your_files Storage Where to place your files on SD Card
  28. 28. Build process Apk file contents
  29. 29.