Android System Architecture Android Application Fundamentals Applications in Android All source code, resources, and data are compiled into a single archive file. The file uses the.apk suffix and is used to install the application on an Android device. Each application lives in its own security sandbox on the Android platform. Apps in the Android OS Android operates as a multi user Linux system. By default each application is run under a unique user ID and its own Linux process. Each process runs in its own VM so applications remain isolated. Each app has access to only necessary components that it needs to operate and nothing more. Program Model PC PC PC 1
Mobile Application Model Mobile devices are enhanced user terminals Main task is user interaction with the data and computing hosted by the cloud Hence the UI becomes a primary component MVC Pattern The model, view, controller pattern is a way of breaking up an application in to three separate sections. Model: The application data and rules. View: The visible part of the application. Controller: The interpreter that mediates data between the view and the model. MVC Pattern In Android we can often think of applications using this pattern. Model can be stored in a Java class containing the data. View is usually the XML Layout file the user sees to interact with our app. Controller is often the Java class used to extend Activity. Interacts with both the Model and the View. MVC Mobile App Model 2
Application Components There are four basic components that are used to build Android applications: Activities Services Content Providers Broadcast Receivers Activities An activity is a single screen for user interface. An application can contain many different activities that operate independently. For example a camera application can have a picture taking activity, a gallery activity, a photo editing activity, etc. Services A service is a component that runs in the background that does not have a user interface. It can be used to perform long running operations, fetch data over a network, and so on. It is used to perform a task without blocking the user interface. Activities Apps are composed of activities Activities are self contained tasks made up of one screen full of information Activities start one another and are destroyed commonly Apps can use activities belonging to another app Much more to come... Content Providers A content provider is a way of managing application data, whether it be shared or private. It can be used to access data that it stored on the system, and SQL database, on the web, or another form of persistent data storage that the app can reach. adapted from Utah CS4962 Matt Stoker 3
Broadcast Receivers A broadcast receiver is a component that responds to system wide announcements. For example a broadcast saying battery is low, the screen was turned off, etc. Generally not used to do much work, but just to handle an event. Activating the Components Content providers are activated when targeted by a request from the ContentResolver. The content resolver handles transactions with the content provider so the requesting component does not need to. This extra layer of abstraction also gives added security. Android App Architecture activity Content provider intent service The Manifest file is an XML file that the system needs in order to properly run an app. It is used to keep record of an application s components, permissions, minimum API Level, required features, and more. All components must be declared or the system will not know they exist. Activating the Components Activities, services, and broadcast receiver components are activated via an intent. An intent is an asynchronous message that binds components to each other at run time. The intent for services and activities define the action to perform. For broadcast receivers the intent defines the announcement being broadcast. Here an activity is declared using it s fully qualified class name as the value of the android:name field and a string for the user visible label in the android:label field. 4
Manifest Example All application components must be declared in this way: <activity> elements for activities <service> elements for services <receiver> elements for broadcast receivers <provider> elements for content providers Declaring App Requirements The wide variety of devices available to Android means you must specify clearly what your app requires. In the Manifest file you list these things in a similar manner to declaring your components. Main ones being: <supports screens> for screen size and density. <uses sdk> for minimum API declaration. Declaring Permissions The Manifest file is also where you provide the required permissions for an application. These permissions grant privileges to the application so it can effect other portions of the system. 5