Android application is composed of following files
- Java classes
- Android manifest
- Resources
- Files
Java classes : Android provides several base classes to develope android application. Class hierarchy diagram is
View : View class in android is used at design time of android application. This class provides all necessary object(button,image,text etc.) for android application. View class is used in android xml file where tree structure provided by android.
Activity : activity class and its subclasses are the ones that provide logic behind the GUI. Actually it corresponds to ViewModel in Model-View-ViewModel architecture pattern (MVVM). Relationship between subclasses of Activity and GUI layout is 1-to-1; normally each subclass of Activity has one GUI layout associated with it and vice-versa. Activity has a lifecycle.
ContentProvider : ContentProvider class and its subclasses correspond to Model in MVVM architecture. In most practical cases it is a wrapper around SQLite database with rather fancy URI-based way to query the database. Theoretically nobody prevents a developer from building ContentProvider which will be using something else instead of DB for storing data. However given that query() method of ContentProvider returns Cursor object which is quite similar to JDBC ResultSet interface and the way how the query is made, nobody would doubt that the real purpose of ContentProviders is to encapsulate a database.
Think of this: Activity is active and running only when its GUI is on foreground. As soon as another Activity GUI comes in front of the current one, the current one stops running even if it was doing something. And what if you need to perform certain operation even when the process which tries to perform it is not on foreground? You can’t do this with Activity. You can’t do this with ContentProvider as well since it does not have its own lifecycle and it can run only while Activity which uses it is active.
Service : Service has a lifecycle. This means that it can be instantiated and run by Android application framework under certain conditions It can be executed even when the process it runs within is not on a foreground. So if you develop Activity which must perform a long running operation which should be completed even while running in background, you should create Service implementing that operation and invoke it from Activity.
BroadcastReceiver : BroadcastReceiver class and its subclasses serve as “subscribers” in communication mechanism implemented by Android application architecture.
Intent : Intent class and its subclasses serve as messages in message passing in communication mechanisms implemented by Android application architecture.
Android manifest : Android manifest is an XML file and it serves several functions. Here is Google description of manifest functions.
- It names the Java package for the application. The package name serves as a unique identifier for the application.
- It describes the components of the application — the activities, services, broadcast receivers, and content providers that the application is composed of.
- It declares which permissions the application must have in order to access protected parts of the API and interact with other applications.
- It declares the minimum level of the Android API that the application requires.
Resources : Any modern GUI application technology uses resources in some form. Android applications are not an exception of the rule. They use following types of resources:
- Pictures
- GUI layouts (XML files)
- Menu definitions (XML files)
- Textual strings
The way resources are referenced by Android applications is somewhat unusual. Normally in Java resources are identified by strings. Such strings may contain e.g. a path and a name of a file containing the picture or an ID of particular string etc. The problem with such approach is that mistakes in those references could not be caught during code translation.
Let’s consider following example. A file named mybutton.png contains a picture for a button. A developer makes a mistake and types mybuton.png as a reference to the resource in the code instead of using the correct file name. As a result the code is instructed to use nonexistent resource, but the code will compile just fine. The mistake may be discovered only during testing (and may not be discovered at all).
Google folks came with an elegant solution to the problem. Android application build generates a special Java class named R (just a single letter name) for each package where classes use resources. This class has a number of static final data members. Each such data member is a reference to a particular resource and they are used in Android Java code for referencing resources. Due to this each mistake in referencing resources is discovered at compile time.
Files : Android applications use several different types of files.
- “General purpose” files
- Database files
- Opaque Binary Blob (OBB) files (those represent encrypted file systems on its own that can be mounted for the application)
- Cached files