reading-notes-ma


Project maintained by mohnalkhateeb Hosted on GitHub Pages — Theme by mattgraham

Android Fundamentals

Application Fundamentals

App components

are the essential building blocks of an Android app. Each component is an entry point through which the system or a user can enter your app.

Activities

An activity is the entry point for interacting with the user. It represents a single screen with a user interface.

Services

A service is a general-purpose entry point for keeping an app running in the background for all kinds of reasons. It is a component that runs in the background to perform long-running operations or to perform work for remote processes.

A broadcast receiver

is a component that enables the system to deliver events to the app outside of a regular user flow, allowing the app to respond to system-wide broadcast announcements. Because broadcast receivers are another well-defined entry into the app, the system can deliver broadcasts even to apps that aren’t currently running.

Content providers

A content provider manages a shared set of app data that you can store in the file system, in a SQLite database, on the web, or on any other persistent storage location that your app can access. Through the content provider, other apps can query or modify the data if the content provider allows it.

Activating components

Three of the four component types—activities, services, and broadcast receivers—are activated by an asynchronous message called an intent. Intents bind individual components to each other at runtime.

The manifest file

Declaring components

The primary task of the manifest is to inform the system about the app’s components. For example, a manifest file can declare an activity as follows:

    <?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>
Declaring component capabilities
    <manifest ... >
        ...
        <application ... >
            <activity android:name="com.example.project.ComposeEmailActivity">
                <intent-filter>
                    <action android:name="android.intent.action.SEND" />
                    <data android:type="*/*" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
        </application>
    </manifest>
Declaring app requirements
    <manifest ... >
        <uses-feature android:name="android.hardware.camera.any"
                    android:required="true" />
        ...
    </manifest>