Professional Documents
Culture Documents
2 - AppDev Android Basics
2 - AppDev Android Basics
TECHNOLOGIES
Lecture 2
Android Basics
• Application Name
• Package name
• Path Location
• Language
• Minimum Required SDK
Running the Application
• Activities
• Services
• Broadcast Receivers
• Content Providers
Anatomy of Android Applications
1. Java
2. res/drawable
3. Res/layout
4. Res/value
5. AndroidManifest.xml
6. Gradle Scripts
Gradle Scripts
<manifest>
This is the root node of each AndroidManifest.xml. It contains the package-attribute,
which points to any package in our Activity.
<application>
Root element containing declarations of the application-level components contained
in the package.
<activity>
An Activity is the primary thing for an application to interact with the user.
AndroidManifest.xml
<intent - filter>
It declares what kind of Intents a component supports.
<action>
An action-type that the component supports.
<category>
A category-type that the component supports
AndroidManifest.xml
<receiver>
An IntentReceiver allows an application to be told about changes to data or actions that
happen, even if it is not currently running
<service>
A Service is a component that can run in the background for an arbitrary amount of time.
<provider>
A ContentProvider is a component that manages persistent data and publishes it for
access by other applications
Main Approaches in Programming app
The application context is the central location for all top-level application
functionality. Use the application context to access settings and resources
shared across multiple activity instances.
Retrieve the application context for the current process by using the
getApplicationContext() method, like this:
Because the Activity class is derived from the Context class, you can use the
“this” object instead of retrieving the application context explicitly when
you’re writing code inside your Activity class.
Using Toast
• Size
android:layout_height,
android:layout_width
match_constraint
wrap_content
Commonly Used Attributes
• android:weight
It controls the resizing behavior of its
child Views. The value is either 0 or 1.
Using a weight of 1 makes the View
stretch, while using 0 will make that
View just as big as needed.
Commonly Used Attributes
• Alignment
android:layout_gravity
android:gravity
Possible values:
top, bottom, left, right, center_vertical, center_horizontal, center,
fill_vertical, fill_horizontal, fill, clip_vertical, clip_horizontal
Commonly Used Attributes
• Margins
android:layout_marginBottom, layout_marginTop
android:layout_marginRight, layout_marginLeft
• Padding
android:paddingBottom, paddingTop
android:paddingRight, paddingLeft
• Color
android:background
android:textColor=“#colorcode”
• Click Handler
android:onClick
Referring to Existing Ids
• First component @+id for assigning a new id
Organizing The Screen
Targeting different screen sizes
• In Android Manifest.xml
<supports-screens>
android:smallScreens=”false”
android:normalScreens=”true”
android:largeScreens=””
android:xlargeScreens=”true”
android:anyDensity=”true”
</supports-screens>
Multiple Screen Support
Reference: https://developer.android.com/guide/practices/screens_support.html