Professional Documents
Culture Documents
1. Linux Kernel: Android uses the Linux kernel as its foundation. The kernel acts as an
abstraction layer between the hardware and the rest of the software stack
2. Native Libraries: Android includes a set of native libraries written in C/C++ that
provide essential system functionalities.
3. Android Runtime (ART): The Android Runtime is responsible for executing and
managing applications on Android devices.
4. Android Framework: The Android framework provides a rich set of APIs and tools
that developers can utilize to build applications.
5. Applications: At the topmost layer are the user applications that run on Android
devices. These applications can be pre-installed system apps (e.g., dialer, messaging),
third-party apps downloaded from the Google Play Store or other sources, or custom-
developed apps.
2.What is activity?
Activity is a fundamental building block of an Android application. It represents a single
screen with a user interface where the user can interact and perform various actions.
Activities serve as the entry point for users to interact with an app and are an essential part of
the Android application lifecycle.
1. Inline OnClickListener:
In this approach, an inline OnClickListener is set directly on the Button object using the
“setOnClickListener” method. It requires implementing the “OnClickListener” interface and
overriding the “onClick” method.
Example:
myButton.setOnClickListener(new View.OnClickListener() {
@Override
});
Alternatively, define the click event handler directly in the XML layout file by specifying the
“android:onClick”attribute for the Button. The method with the same name as specified in the
“android:onClick” attribute will be automatically called when the button is clicked.
Example:
<Button
android:id="@+id/myButton"
android: layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me"
android:onClick="onButtonClick" />
3. View.OnClickListener Interface:
Example:
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myButton.setOnClickListener(this);
@Override
if (v.getId() == R.id.myButton) {
3. onResume(): Activity gains user focus, start animations, and initialize resources.
The framework includes a wide range of libraries, APIs, and system resources that enable
developers to perform various tasks, such as user interface management, resource
management, data storage and retrieval, network connectivity, and more.
The framework also encompasses essential functionalities like activity lifecycle management,
inter-component communication, data sharing between applications, location-based services,
and notification handling.
6. Discuss the differences of Linear Layout and Relative
layout and highlight their advantages and disadvantages
with examples.
LinearLayout and RelativeLayout are two commonly used layout managers in Android for
arranging and positioning UI elements. Here are the differences between the two layouts,
along with their advantages and disadvantages:
1. LinearLayout:
- LinearLayout arranges child views linearly either horizontally or vertically, based on the
orientation set.
- LinearLayout is suitable for creating simple, linear UI designs where elements are
arranged sequentially.
- Example: Consider a login screen with two EditText fields and a login button placed
vertically using a LinearLayout.
Advantages of LinearLayout:
Disadvantages of LinearLayout:
2. RelativeLayout:
- RelativeLayout allows positioning of child views relative to each other or relative to the
parent.
- It provides more flexibility in creating complex UI designs with relative positioning and
alignment.
- RelativeLayout is suitable when you need to create dynamic layouts that adapt to different
screen sizes and orientations.
- Example: Consider a chat message layout with an image, sender name, and message text
positioned relative to each other using a RelativeLayout.
Advantages of RelativeLayout:
- Well-suited for complex UI designs with varying screen sizes and orientations.
Disadvantages of RelativeLayout:
- More complex layouts may require nested RelativeLayouts, which can lead to reduced
efficiency.
In summary, LinearLayout is suitable for simple linear layouts, while RelativeLayout offers
more flexibility for complex UI designs with relative positioning. The choice between the
two depends on the specific requirements of your UI design and the desired trade-offs
between simplicity and flexibility.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textView"
</RelativeLayout>
</LinearLayout>