Android
Android
1. linux kernel
2. native libraries (middleware),
3. Android Runtime
4. Application Framework
5. Applications
1) Linux kernel
2) Native Libraries
On the top of linux kernel, their are Native libraries such as WebKit, OpenGL,
FreeType, SQLite, Media, C runtime library (libc) etc.
The WebKit library is responsible for browser support, SQLite is for database,
FreeType for font support, Media for playing and recording audio and video formats.
3) Android Runtime
In android runtime, there are core libraries and DVM (Dalvik Virtual Machine) which
is responsible to run android application. DVM is like JVM but it is optimized for mobile
devices. It consumes less memory and provides fast performance.
4) Android Framework
On the top of Native libraries and android runtime, there is android framework.
Android framework includes Android API's such as UI (User Interface), telephony,
resources, locations, Content Providers (data) and package managers. It provides a lot of
classes and interfaces for android application development.
5) Applications
On the top of android framework, there are applications. All applications such as
home, contact, settings, games, browsers are using android framework that uses android
runtime and libraries. Android runtime and native libraries are using linux kernal.
1. Manifests Folder
2. Java Folder
3. res (Resources) Folder
• Drawable Folder
• Layout Folder
• Mipmap Folder
• Values Folder
4. Gradle Scripts
1. Manifests Folder
Manifests folder contains AndroidManifest.xml for creating our android application.
This file contains information about our application such as the Android version,
metadata, states package for Kotlin file, and other application components. It acts as an
intermediator between android OS and our application.
2. Java folder
The Java folder contains all the java and Kotlin source code (.java) files that we create
during the app development, including other Test files.
res/drawable folder
It contains the different types of images used for the development of the
application. We need to add all the images in a drawable folder for the application
development.
res/layout folder
The layout folder contains all XML layout files which we used to define the user
interface of our application. It contains the activity_main.xml file.
res/mipmap folder
This folder contains launcher.xml files to define icons that are used to show on the
home screen. It contains different density types of icons depending upon the size of the
device such as hdpi, mdpi, xhdpi.
res/values folder
Values folder contains a number of XML files like strings, dimensions, colors, and
style definitions. One of the most important files is the strings.xml file which contains the
resources.
Main Components
1. Activities
They dictate the UI and handle the user interaction to the smart phone screen.
2. Services
3. Broadcast Receivers
4. Content Providers
They handle data and database management issues. A content provider component
supplies data from one application to others on request.
Additional Components
There are additional components which will be used in the construction of above
mentioned entities, their logic, and wiring between them. These components are −
1. Fragments
2. Views
UI elements that are drawn on-screen including buttons, lists forms etc.
3. Layouts
View hierarchies that control screen format and appearance of the views.
4. Intents
5. Resources
6. Manifest
What is an activity?
An activity represents a single screen with a user interface just like window. It has a
lifecycle that includes methods such as onCreate(), onStart(), onResume(), onPause(), onStop(),
and onDestroy().
onStart()
This callback is called when the activity becomes visible to the user.
onResume()
This is called when the user starts interacting with the application.
onPause()
The paused activity does not receive user input and cannot execute any code and called
when the current activity is being paused and the previous activity is being resumed.
onStop()
This callback is called when the activity is no longer visible.
onDestroy()
This callback is called before the activity is destroyed by the system.
onRestart()
This callback is called when the activity restarts after stopping it.
We can also pass the information from one activity to another using explicit intent.
MainActivity.java
Intent intent = new Intent(MainActivity.this,ResultActivity.class);
intent.putExtra("Key","Enter Data Here");
startActivity(intent);
AnotherActivity.java
Intent intent = getIntent();
String s=intent.getStringExtra("Key"));
Resource Type
Animation resources
Define pre-determined animations.
Tween animations are saved in res/anim/ and accessed from the R.anim class.
Frame animations are saved in res/drawable/ and accessed from
the R.drawable class.
Color state list resource
Define a color resource that changes based on the View state.
Saved in res/color/ and accessed from the R.color class.
Drawable resources
Define various graphics with bitmaps or XML.
Saved in res/drawable/ and accessed from the R.drawable class.
Layout resource
Define the layout for your application UI.
Saved in res/layout/ and accessed from the R.layout class.
Menu resource
Define the contents of your application menus.
Saved in res/menu/ and accessed from the R.menu class.
String resources
Define strings, string arrays, and plurals and include string formatting and
styling.
Saved in res/values/ and accessed from the R.string, R.array,
and R.plurals classes.
Style resource
Define the look and format for UI elements.
Saved in res/values/ and accessed from the R.style class.
Font resources
Define font families and include custom fonts in XML.
Saved in res/font/ and accessed from the R.font class.
More resource types
Define other primitive values as static resources, including the following:
Bool
Color
ID
Integer
Integer array
Typed array
XML resource that provides a TypedArray, which you can use for an
array of drawables.
Example
Here first line of the code make use of R.id.myimageview to get ImageView
defined with id myimageview in a Layout file. Second line of code makes use
of R.drawable.myimage to get an image with name myimage available in
drawable sub-directory under /res.
Example
Now you can set the text on a TextView object with ID msg using a resource ID as
follows −
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a TextView" />
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a Button" />
</LinearLayout>
This application code will load this layout for an Activity, in the onCreate()
method as follows −
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
Accessing Resources in XML
Now you can use these resources in the following layout file to set the text
color and text string as follows −
EditText
Purpose: Used for accepting user input in the form of text.
Key Attributes:
android:inputType: Specifies the type of input expected (text, number, email, etc.).
android:hint: Provides a hint or placeholder text.
android:maxLength: Limits the maximum number of characters that can be entered.
android:password: Indicates whether the input should be treated as a password
(characters are masked).
Example:
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="Enter text here"/>
TextView
Purpose: Used for displaying text to the user.
Key Attributes:
android:text: Sets the text to be displayed.
android:textSize: Specifies the size of the text.
android:textColor: Defines the color of the text.
android:gravity: Controls the alignment of the text within the TextView.
Example:
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, World!"
android:textSize="18sp"
android:textColor="#000000"
android:gravity="center"/>
Button
Purpose: Used to trigger an action when clicked.
Key Attributes:
android:text: Sets the text displayed on the button.
android:onClick: Specifies the method to be called when the button is clicked.
Example:
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me"
android:onClick="onButtonClick"/>