Android Notes
Android Components
- Activity - Entry point for user interaction (UI).
- Service - Entry point for long-running background processes.
- Broadcast Receiver - Enables the system to deliver events to the app, outside a regular user interaction flow.
- Content Provider - Manages shared sets of app data that can be stored on the file system.
See - developer.android.com/guide/components/fundamentals
Links
Storage
Application Components
- 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.
- Broadcast Receivers - 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.
- https://developer.android.com/guide/components/broadcasts
- Sublcass https://developer.android.com/reference/android/content/BroadcastReceiver
- Delivered as https://developer.android.com/reference/android/content/Intent
- https://developer.android.com/reference/android/app/job/JobService
- https://developer.android.com/reference/android/app/job/JobScheduler
- https://developer.android.com/reference/android/content/Context#registerReceiver(android.content.BroadcastReceiver,%20android.content.IntentFilter)
- 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.
- https://developer.android.com/reference/android/content/ContentProvider
- https://developer.android.com/guide/topics/providers/content-providers
- Are activated when targeted by a request from a https://developer.android.com/reference/android/content/ContentResolver
startActivity
()startActivityForResult
()- Android 5+ -
JobScheduler
- Initiate a broadcast by passing an Intent to methods such as
sendBroadcast()
,sendOrderedBroadcast
(), orsendStickyBroadcast
(). - Perform a query to a content provider by calling
query
() on aContentResolver
.
See Also
Application Manifest
The [[https://developer.android.com/guide/topics/manifest/manifest-intro|AndroidManifest.xml]] file configures the Android application.
You can use an Intent
to start activities, services, and broadcast receivers.
<?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>
Intent Filter
Uses [[https://developer.android.com/reference/android/content/Intent#ACTION_SEND|Intent#ACTION_SEND]].
<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>
Tags
<application>
element.android:icon
attribute points to resources for an icon that identifies the app.
<activity>
elements for activities.android:name
specifies the fully qualified class name of theActivity
subclass.android:label
specifies a string to use as the user-visible label for the activity.
<service>
elements for services.<receiver>
elements for broadcast receivers.<provider>
elements for content providers.<intent-filter>
The system identifies the components that can respond to an intent by comparing the intent received.
Features
- User Permissions.
- Declares minimum API required.
- Declares hardware and software used or required.
- Declares API libraries for linking. (other than the Android.jar)
See Also
- https://developer.android.com/guide/topics/manifest/application-element
- https://developer.android.com/guide/topics/manifest/activity-element
- https://developer.android.com/guide/topics/manifest/service-element
- https://developer.android.com/guide/topics/manifest/receiver-element
- https://developer.android.com/guide/topics/manifest/provider-element
- https://developer.android.com/guide/topics/manifest/intent-filter-element
Declaring app requirements
build.gradle
Always edit minSdkVersion
and targetSdkVersion
in the gradle build file not the manifest.
Example - Camera API added in API 26, the minSdkVersion
must be equal to or greater than 26 to access the Camera API.
Devices that do not have a camera or have an Android version lower than 8.0 cannot install your app from Google Play.
android { //... defaultConfig { //... minSdkVersion 26 targetSdkVersion 29 }}
In the app manifest:
name
- The qualified name of the feature.required
- The API is not actually required to RUN the app, functionality may not be 100%.
<manifest ... > <uses-feature android:name="android.hardware.camera.any" android:required="true" /> ...</manifest>
See
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 app code or from other resources defined in XML
- Drawables -
res/drawable/
==R.drawable.logo
- String translation -
res/values-fr/
Resource Types
- animator - XML files that define property animations.
- anim - XML files that define tween animations.
- color - XML files that define a state list of colors.
- drawable - Bitmap files (.png, .9.png, .jpg, .gif) or XML files
- Bitmap files
- Nine-Patches (re-sizable bitmaps)
- State lists
- Shapes
- Animation drawables
- Other drawables
- Drawable Resources
- mipmap - Drawable files for different launcher icon densities.
- layout - XML files that define a user interface layout.
- menu - XML files that define app menus, such as an Options Menu, Context Menu, or Sub Menu.
- raw - Arbitrary files to save in their raw form.
- values - XML files that contain simple values, such as strings, integers, and colors.
- arrays.xml - https://developer.android.com/guide/topics/resources/more-resources#TypedArray
- colors.xml - https://developer.android.com/guide/topics/resources/more-resources#Color
- dimens.xml - https://developer.android.com/guide/topics/resources/more-resources#Dimension
- strings.xml - https://developer.android.com/guide/topics/resources/string-resource
- styles.xml - https://developer.android.com/guide/topics/resources/style-resource
- xml - Arbitrary XML files that can be read at runtime.
- font - Font files with extensions such as .ttf, .otf, or .ttc, or XML files that include a <font-family> element.