Android Journal Theory
Android Journal Theory
Name: ______________________________________
This lab book will be considered as Journal for final practical exam.
Prepared by:
Reviewed by:
14
5
Question21: Create an Android App with Login
Screen. On successful login, gives message go
21 to next Activity (Without Using Database& use
Table Layout).
23
29
31
7
Questio32: Create an Android Application that
Demonstrate GridView and Onclick of Item
Display the Toast.
32
38
8
Question39: Create a Custom ListView in Android
39
Application.
Question40: Create a Simple Android
40 Application to calculate age of a person. (Use
Table Layout)
Theory Questions:
Question 1: Explain Android Adapters.
9
implementation of methods such as getItemCount(), onCreateViewHolder(),
and onBindViewHolder().
Explicit Intents: Explicit Intents are used when developers have a specific
target component in mind within their application. They explicitly specify the
component's class name or its package and class name. Explicit Intents are
typically used for intra-application communication.
Example:
10
Intent explicitIntent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(explicitIntent);
Implicit Intents: Implicit Intents are utilized when developers want the Android
system to determine the appropriate component to handle a particular action
based on its intent filters. They declare an action to be performed, such as
viewing a webpage or sending an email, without explicitly specifying the
target component. The system then resolves the Intent and launches the
appropriate component from any application that can handle the specified
action.
Example:
11
Created: The activity is created but not yet visible to the user. This occurs
when the onCreate() method is called. Here, you typically initialize essential
components and set up the UI.
Started: The activity is visible but not yet in the foreground. This state is
reached when the onStart() method is called. Here, you can perform actions
like registering broadcast receivers or preparing data.
Resumed: The activity is in the foreground and has user focus. This is when
the onResume() method is called. It's where you start animations, play
sounds, and handle user interactions.
Paused: Another activity partially obscures the activity, but it's still visible. This
state is reached when the onPause() method is called. Use this state to
release resources not needed when the activity is not visible.
Stopped: The activity is no longer visible to the user. This occurs when the
onStop() method is called. You should release resources here, as the activity
may be destroyed soon.
Destroyed: The activity is being destroyed, either because the user finished it
or the system needs to free resources. The onDestroy() method is called at
this stage, where you should release any resources and unregister any
listeners.
Restarted: The activity is restarted after being stopped. This state is reached
when the activity is brought back to the foreground from a stopped state. The
onRestart() method is called before onStart().
12
Question 4: How to create AVD’s?
To create Android Virtual Devices (AVDs), you can follow these steps:
Access AVD Manager: Go to the "Tools" menu and select "AVD Manager."
Alternatively, you can click on the AVD Manager icon in the toolbar.
Create New Virtual Device: In the AVD Manager window, click on the "Create
Virtual Device" button.
Choose Device Definition: Select a device definition from the list. This
represents the device model and hardware specifications of the virtual device
you want to create. Click "Next."
Select System Image: Choose the system image for the Android version you
want to run on the virtual device. If you haven't downloaded the desired system
image, click on the "Download" link next to it. Once downloaded, select the
system image and click "Next."
Configure Virtual Device: Customize the AVD configuration settings such as the
device name, orientation, and more. Adjust the settings according to your
requirements and click "Finish."
Launch Virtual Device: Back in the AVD Manager, select the newly created
virtual device from the list and click on the green "Play" button to launch it.
Use Virtual Device: Once the virtual device is launched, it will emulate an
Android device environment on your computer. You can interact with it just like
a physical Android device, testing your applications or performing debugging
tasks.
Creating AVDs allows you to simulate various Android device configurations,
enabling you to test your applications across different screen sizes, resolutions,
and Android versions without needing physical devices.
13
Question 5: Write in detail about Manifest File.
The manifest file declares the building blocks of your application. These
include:
Activities: The different screens users can interact with in your app (e.g., a
main menu, settings screen).
Services: Background processes that run without a direct user interface (e.g., a
music player service).
Broadcast Receivers: Components that respond to system events or
broadcasts sent by other apps (e.g., handling network connectivity changes).
Content Providers: Act as a centralized data repository that other apps can
access (e.g., a content provider for your app's settings).
For each component, the manifest specifies its corresponding Java or Kotlin
class name, allowing the system to identify and launch them.
2. App Metadata:
The manifest file also stores essential app information, including:
Package Name: A unique identifier for your app, like a domain name for
websites.
Version Name and Code: The human-readable version (e.g., 1.0.0) and an
internal version code (e.g., 1).
Application Name: The name displayed to users on the launcher screen.
Icons: Defines the app icons for different device launcher sizes.
Minimum and Target SDK Versions: Specifies the minimum Android API level
your app requires to run and the target version it's optimized for.
14
3. Permissions and Capabilities:
The manifest file is where you declare the permissions your app needs to
access specific features or resources on the device. For instance, accessing
camera functionality requires the CAMERA permission.
Additionally, you can specify hardware and software capabilities your app relies
on, influencing device compatibility.
15
:
One of the key features of the Android SDK is the Android Emulator.
This emulator allows you to test and debug your Android
applications without needing a physical Android device.
16
:
17
:
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Action to perform when the button is clicked
Toast.makeText(getApplicationContext(), "Button Clicked",
Toast.LENGTH_SHORT).show();
}
});
spinner.setOnItemSelectedListener(new
AdapterView.OnItemSelectedListener() {
@Override
18
:
@Override
public void onNothingSelected(AdapterView<?> parent) {
// Action to perform when nothing is selected
}
});
Question 9 List Basic Views and explain any three with example.
19
:
TextView:
Example:
xml
Copy code
<TextView
android:id="@+id/text_view"
20
:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, World!"
android:textSize="18sp"
android:textColor="#000000" />
Explanation: The TextView displays text on the screen. In the
example above, it shows "Hello, World!" with a text size of 18sp and
black text color. TextViews are commonly used to display static text
or dynamically updated content in an Android app.
EditText:
Example:
xml
Copy code
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your name"
android:inputType="text" />
Explanation: The EditText allows users to input text. In the example
above, it provides a hint "Enter your name" to guide the user.
21
:
EditTexts are frequently used for capturing user input such as text,
numbers, or passwords in forms or search bars.
Button:
Example:
xml
Copy code
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me" />
Explanation: The Button triggers an action when clicked. In the
example above, it displays the text "Click Me". Buttons are commonly
used to initiate operations or navigate to different screens within the
app. They can be customized with text, icons, and background colors
to suit the app's design.
22
Question 10: Explain Dialog Box
Purpose:
o Similar to general dialog boxes, Android dialogs are used for:
Types of Dialogs:
o Android offers various pre-built dialog classes for common use
cases:
AlertDialog: The most common type, for displaying
23
o Android dialogs are modal by default, meaning they block
interaction with the underlying app screen until the user
dismisses them (typically by clicking a button).
o They can be customized with titles, icons, and various button
configurations depending on the dialog type.
Overall, Android dialogs provide a standardized way to interact with
users, ensuring a consistent experience across different apps. By
using the appropriate dialog type and tailoring it to your specific needs,
you can effectively communicate with users and guide them through
your app's functionalities.
24