You are on page 1of 9

CSE 2200

Software Development III


Assignment 02

Name : Md Mostafizur Rahman


ID : 20210104151
Section : C [2]
1.Describe architecture of android?
Android is an open-source operating system primarily designed for mobile devices such as
smartphones and tablets. It is based on the Linux kernel and developed by Google. The
architecture of Android is built upon multiple layers, each responsible for different
functionalities and components. Here's an overview of the Android architecture:

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.

Each Activity is typically implemented as a subclass of the “android.app. Activity” class


and corresponds to a specific user interface layout defined in an XML file. The Activity class
provides methods and callbacks to handle user interactions, manage the lifecycle, and handle
other application-related tasks.
3. In how many ways click events of Button can be
handled? Discuss them with examples.
In Android, there are multiple ways to handle click events for a Button or any other UI
component. Here are the three most commonly used approaches:

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:

Button myButton = findViewById(R.id.myButton);

myButton.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

// Perform actions when the button is clicked

});

2. XML onClick attribute:

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:

This approach involves implementing the “OnClickListener” interface directly in the


Activity class and assigning it to the Button using the “setOnClickListener” method.

Example:

public class MyActivity extends AppCompatActivity implements View.OnClickListener {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Button myButton = findViewById(R.id.myButton);

myButton.setOnClickListener(this);

@Override

public void onClick(View v) {

if (v.getId() == R.id.myButton) {

// Perform actions when the button is clicked

4. Describe activity life cycle of Android.


The Activity lifecycle in Android describes the various states and transitions an Activity goes
through during its lifetime. Here’s an overview of the Activity lifecycle:

1. onCreate(): Initialize components and perform setup tasks.

2. onStart(): Activity becomes visible, but not in the foreground.

3. onResume(): Activity gains user focus, start animations, and initialize resources.

4. onPause(): Activity loses focus, release resources and save data.

5. onStop(): Activity is no longer visible, release unnecessary resources.

6. onRestart(): Activity is being restarted after being stopped.

7. onDestroy(): Activity is being destroyed, release resources and perform cleanup.

5. Explain android framework.


The Android framework is a software platform developed by Google for building mobile
applications on Android devices. It provides a foundation and a set of tools that developers
can utilize to create robust and feature-rich Android applications.

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.

- It is simple to use and has less overhead in terms of performance.

- 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:

- Easy to understand and implement.

- Lightweight and performs well for simple layouts.

- Supports weight attribute to distribute space proportionally among child views.

Disadvantages of LinearLayout:

- Limited flexibility in complex UI designs.

- Can lead to nested layouts to achieve desired arrangements.

- Difficulty in handling overlapping or relative positioning of views.

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:

- Flexibility in positioning views relative to each other.

- Supports alignment options such as alignParentStart, alignParentEnd, alignStart, alignEnd,


etc.

- Well-suited for complex UI designs with varying screen sizes and orientations.

Disadvantages of RelativeLayout:

- Can be more challenging to understand and manage compared to LinearLayout.

- Relatively higher overhead in terms of performance compared to LinearLayout.

- 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.

7. Explain the importance of AndroidManifest.xml file.


The AndroidManifest.xml file is vital for an Android application as it serves as a declaration
file that provides important information to the Android operating system. It identifies the
application, specifies permissions, declares components like activities and services, defines
intent filters, configures the application, and determines its behavior and lifecycle. It plays a
crucial role in installation, execution, and management of the application, ensuring proper
functioning,security, and compatibility with the Android ecosystem .

8. What is Android SDK?


The Android SDK (Software Development Kit) is a set of tools, libraries, and resources
provided by Google for developing Android applications. It includes development tools like
Android Studio, APIs for interacting with the Android operating system, an emulator for
testing apps, documentation and sample code, support libraries, and build tools. The Android
SDK is essential for developers to create, test, and deploy Android applications, providing the
necessary resources and functionalities for building robust and feature-rich apps.

9. Discuss nesting of layouts with examples.


Nesting layouts in Android refers to the practice of placing one layout inside another layout
to achieve complex and flexible UI designs. By nesting layouts, developers can create
hierarchical structures, group related UI elements, and control the positioning and behavior of
the user interface. An example would be RelativeLayout inside LinearLayout :

<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"

android:text="Hello World!" />

<Button

android:id="@+id/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@id/textView"

android:text="Click " />

</RelativeLayout>

</LinearLayout>

You might also like