0% found this document useful (0 votes)
5 views

AndroidPYQ

Uploaded by

onpointads91
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

AndroidPYQ

Uploaded by

onpointads91
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

What is a Native App?

A native app is a software application built specifically for a particular platform or operating
system (e.g., Android or iOS) using platform-specific programming languages, tools, and
frameworks.

 For Android: Java or Kotlin


 For iOS: Swift or Objective-C

Native apps are downloaded and installed from app stores like Google Play or Apple App
Store, and they leverage the device’s hardware and software features efficiently.

Pros of Native Apps:

1. Performance:
o Native apps are faster and more efficient as they are optimized for the specific
platform.
2. Access to Device Features:
o They can directly access hardware features like the camera, GPS, microphone,
etc.
3. User Experience:
o Native apps follow the platform's UI/UX design guidelines, ensuring a
seamless user experience.
4. Offline Functionality:
o They can work offline or with limited internet connectivity.
5. Security:
o Native apps are more secure because they use platform-specific security
features.

Cons of Native Apps:

1. High Development Cost:


o Building separate apps for iOS and Android can be expensive.
2. Time-Consuming:
o Developing and maintaining two separate codebases takes more time.
3. Platform Dependency:
o The app can only run on the platform it’s built for unless you create a version
for another platform.
4. App Store Approval:
o Publishing native apps requires adhering to app store guidelines, which can
delay releases.
Aspect Native App Web App
Built for specific platforms Runs on web browsers and is platform-
Platform
(Android/iOS) independent
High, as it leverages platform- Lower, as it depends on browser
Performance
specific features capabilities
Separate codebases for each
Development Single codebase (HTML, CSS, JavaScript)
platform
Accessed via a web browser, no
Installation Installed via app stores
installation required
Requires an internet connection (unless it's
Offline Access Works offline
a progressive web app)
Device Limited access (via browser APIs, such as
Full access to hardware features
Features geolocation or camera)
Updates are immediate and require no user
Updates Requires app store updates
action
Lower cost, as a single app works across
Cost Higher cost for separate apps
devices

Q2 - Why Toggle buttons are used? How Toggle buttons are


differing than
Switch. Explain with example.

Toggle buttons are used to enable or disable a specific functionality or to switch between
two states. They represent an on/off or selected/unselected condition, and the user can toggle
between these states by clicking or tapping the button.

Key Use Cases:

 Switching modes (e.g., dark mode vs. light mode).


 Turning a feature on or off (e.g., enabling/disabling notifications).
 Selecting one option from multiple mutually exclusive options (e.g., bold/italic in a
text editor).

Definition of Switch

A switch is a user interface element that allows users to toggle between two mutually
exclusive states, such as ON and OFF, or Enabled and Disabled. It visually resembles a
physical toggle switch and is commonly used in settings to activate or deactivate a specific
feature or functionality.

Key Features of a Switch:

1. Binary Choice: Represents two states only (e.g., on/off, active/inactive).


2. Intuitive Design: Its sliding or flipping motion is familiar and easy to understand.
3. Real-Time Feedback: Switching states instantly reflects the change in the system
(e.g., turning Wi-Fi on or off).

Difference Between Toggle Button and Switch:

Aspect Toggle Button Switch


Often represented as a button or icon Looks like a physical switch (sliding or
Appearance
that toggles state. flipping action).
Indicates a selection or performs an Used specifically for
Purpose
action. enabling/disabling settings.
Usually used in UI elements like Found in settings screens for binary
Use Case
toolbars or menus. choices.
State State can be represented by text, State is represented by position (e.g.,
Indicator icons, or color change. left/off, right/on).
Clicking/tapping toggles the state of Sliding or tapping toggles the state of
Behavior
the button. the switch.

Q3- How do you find memory leaks in the mobile app on the
Android
Platform ?

Memory leaks happen when your app keeps holding onto objects (like
Activities or Views) that are no longer needed. This wastes memory and
can slow down or crash your app. Here's how you can find and fix them:

Key Tools:

1. Android Studio Profiler: Find memory usage and leaks.


2. LeakCanary: Easy-to-use library that detects leaks automatically.
3. Logcat: Check for memory-related warnings like OutOfMemoryError.

Q4-What is Toast ? What are the features of Toast? Write down


the syntax
to create a toast.

What is Toast in Android?

A Toast is a small, temporary message that appears at the bottom of the screen (or a custom
position) to provide feedback or information to the user. It doesn’t block user interaction and
disappears automatically after a short time.
Features of Toast:

1. Temporary Display: It disappears automatically after a few seconds.


2. Non-Blocking: It doesn't interrupt or block the user’s interaction with the app.
3. Customizable: You can customize the position, duration, and even the layout of a
toast.
4. Lightweight: It is a simple and efficient way to display brief information.

Syntax to Create a Toast:

Basic Syntax:

Toast.makeText(context, "Your message here", Toast.LENGTH_SHORT).show();

Key Points About Toast:

 Toast is best for short, non-critical messages like "Message sent" or "File
downloaded."
 Avoid overusing toasts, as too many can overwhelm or annoy users.
 For long-term or interactive notifications, use a Snackbar or Dialog instead.

Q5-Why SQLite is used in Android ? Explain with example.

Why is SQLite Used in Android?

SQLite is a lightweight, self-contained database engine included in Android. It is used for


local data storage within an Android application, enabling apps to manage and store data in a
structured format (rows and columns). SQLite is commonly used for small to medium-sized
databases, such as user data, app settings, or offline caching.

Key Reasons to Use SQLite in Android

1. Built-In: No external dependencies; SQLite is embedded in Android by default.


2. Lightweight: It uses minimal resources, making it efficient for mobile apps.
3. SQL Support: Supports standard SQL commands like SELECT, INSERT, UPDATE, and
DELETE.
4. Persistent Storage: Stores data persistently on the device, even if the app is closed.
5. Simple API: Easy to integrate with Android through classes like SQLiteOpenHelper.

Advantages of SQLite in Android

1. Offline Support: Stores data locally, ideal for offline use cases.
2. Fast and Efficient: Provides fast read/write operations.
3. No Server Required: Everything runs locally on the device.
4. Small Footprint: Optimized for mobile devices.
Example Use Cases

1. Storing user preferences, app settings, or session data.


2. Creating offline storage for e-commerce apps, like cart details.
3. Caching data for news apps or social media feeds.
4. Managing structured data, such as user details or product catalogs.

Q6-What is fragment ? Why fragment is used in android ?

What is a Fragment in Android?

A Fragment is a reusable UI component or portion of a user interface in an Android


application. It is a part of an activity, and multiple fragments can be combined within an
activity to create a dynamic UI. Fragments can be used independently or with other
fragments, making it easier to design flexible and modular UIs.

Why Are Fragments Used in Android?

1. Modular UI Design: Allows designing separate portions of the UI as reusable


components.
2. Flexible Layouts: Enables different layouts for different screen sizes (e.g., tablets vs
phones).
3. Reusability: Fragments can be reused in multiple activities or parts of the app.
4. Dynamic UI: Fragments can be added, removed, or replaced dynamically at runtime.
5. Better Performance: Reduces redundancy in the app, leading to better performance
and maintainability.

Q7-Draw and explain the architecture of android.

Architecture of Android

Android's architecture is designed in layers, allowing flexibility, modularity, and efficient


interaction between hardware and software. Here's an explanation of the architecture,
followed by a diagram.

1. Layers in Android Architecture

Android architecture consists of five main layers, from top to bottom:

1.1 Applications Layer

 This is the topmost layer where all Android apps reside (both system and user-
installed apps).
 Examples: Messaging, Contacts, Camera, etc.
 Apps are written in Java, Kotlin, or other supported languages and run in the Android
runtime environment.

1.2 Application Framework

 Provides reusable classes and services for app developers.


 Manages basic functionalities like activity lifecycle, UI management, and resource
handling.
 Key Components:
o Activity Manager: Manages activity lifecycle.
o Window Manager: Handles the display and UI components.
o Content Providers: Manages data sharing between apps.
o View System: Handles UI elements like buttons, text, etc.
o Package Manager: Handles app installation and updates.
o Notification Manager: Displays notifications.

1.3 Android Runtime (ART) and Libraries

 Android Runtime (ART):


o Executes Android apps in a managed environment.
o Uses Ahead-of-Time (AOT) and Just-In-Time (JIT) compilation for better
performance.
 Core Libraries:
o Provide essential functions for app development (like data structures, I/O,
etc.).
o Examples: Dalvik libraries, SQLite, SSL, etc.

1.4 Native C/C++ Libraries

 Built using C and C++, these libraries support high-performance features and
functionalities.
 Examples:
o Surface Manager: Manages display and graphics.
o OpenGL ES: Supports 2D and 3D rendering.
o WebKit: Manages web browsing.
o SQLite: Database engine.
o Media Framework: Supports audio and video playback.

1.5 Linux Kernel

 The foundation of Android architecture.


 Manages hardware-level interactions and device resources like memory, power, and
drivers.
 Key Features:
o Device Drivers: Drivers for camera, Bluetooth, Wi-Fi, etc.
o Memory Management: Efficiently manages RAM usage.
o Power Management: Handles battery performance and power usage.
Diagram: Android Architecture

Here is a textual representation of the architecture diagram:

markdown
Copy code
-------------------------------------------------------
| Applications |
| (System apps like Contacts, Messaging, User Apps) |
-------------------------------------------------------
| Application Framework |
| (Activity Manager, Window Manager, etc.) |
-------------------------------------------------------
| Android Runtime (ART) and Libraries |
| (Core Libraries, SQLite, OpenGL, etc.) |
-------------------------------------------------------
| Native C/C++/JAVA Libraries |
| (WebKit, Media Framework, Surface Manager, etc.) |
-------------------------------------------------------
| Linux Kernel |
| (Device Drivers, Memory Management, Power, etc.) |
-------------------------------------------------------

Explanation of Interaction

 The Linux Kernel interacts directly with hardware.


 The Native Libraries build upon the kernel to offer high-performance services.
 The ART and Core Libraries provide a runtime environment for Android apps.
 The Application Framework acts as a bridge, providing APIs to app developers for
building user-friendly applications.
 Finally, the Applications Layer contains the apps that end-users interact with.

Advantages of Android's Architecture

1. Modularity: Different layers allow easy upgrades and replacements without affecting
other parts.
2. Reusability: Core functionalities (like SQLite) can be reused across apps.
3. Security: The architecture ensures better isolation and security for apps and data.

Q8-What is Service ? Why service is an important component of Android ?


How Service is differing than Broadcast Receiver ?

What is a Service in Android?

A Service in Android is a background component that performs long-running tasks without a


user interface. It is primarily used to execute operations like downloading files, playing
music, or handling network transactions, even when the app is not visible to the user.
Why is Service an Important Component in Android?

1. Background Processing: Services enable applications to continue tasks in the


background (e.g., downloading data or playing music).
2. No UI Required: Services operate independently of the app's user interface, allowing
tasks to continue even if the app is closed.
3. Task Management: Handles operations that need to run consistently, such as syncing
data or checking for updates.
4. Efficient Resource Usage: Allows shared resources to be managed effectively across
the app.

Types of Android Services

1. Foreground Service:
o Runs in the foreground and requires a notification to indicate that it is running.
o Example: Music player showing a notification for playback controls.
2. Background Service:
o Runs in the background without user interaction.
o Example: Syncing data to a server.
o Since Android 8.0 (Oreo), restrictions have been placed on background
services.
3. Bound Service:
o Binds an activity or other component to the service for interaction.
o Example: Apps communicating with a server via a bound service.

A Broadcast Receiver in Android is a component that listens for system-wide or app-


specific broadcast messages and reacts to them. These broadcasts are sent by either the
system (like changes in network connectivity, battery status, etc.) or by other applications. A
broadcast receiver allows an application to be notified of events that occur outside its own
scope.

How is a Service Different from a Broadcast Receiver?

Aspect Service Broadcast Receiver


Performs background tasks that can Listens for and reacts to broadcasted
Purpose
run indefinitely. system or app events.
Runs as long as needed (or until Executes only for a short duration to
Lifespan
explicitly stopped). handle the event it is registered for.
User Does not have a user interface but
No user interface; entirely event-driven.
Interaction can work alongside the app's UI.
Example - Playing music - Responding to system events (e.g., low
Usage - Syncing data battery)
Aspect Service Broadcast Receiver
- Downloading files - Listening for custom app broadcasts.
Execution Triggered when a broadcast (system or
Runs in the background as a
custom) is sent and runs only
continuous process.
momentarily.
Can be started manually or bound Automatically triggered by broadcasts
Triggering
to a component (like Activity). (e.g., alarms, connectivity changes).

Q9-Write down the short notes on the following : (CO4)


(i) Auto Complete Text View
(ii) Edit Text

i) AutoCompleteTextView in Android

AutoCompleteTextView is a subclass of the EditText widget in Android that provides


suggestions to users as they type. It is used to help users complete their input based on the
data available (e.g., a list of previously entered values, contacts, or predefined options). It
enhances the user experience by offering auto-suggestions and saving time.

Features:

 Shows a drop-down list of suggestions based on user input.


 Can be populated with suggestions from various sources, such as an array, database,
or web API.
 Often used for search bars or user input fields where users can select from predefined
values.

ii) EditText in Android

EditText is a user interface element in Android used for text input. It allows users to enter
and modify text through the device's keyboard. It is the most commonly used widget for
gathering user input such as names, emails, passwords, etc.

Features:

 Text Input: Supports different types of text input, such as plain text, passwords,
numbers, etc.
 Customizable: You can customize the input behavior using input types, filters, and
other attributes.
 Focusable: It is focusable, meaning the user can interact with it, and it can bring up
the keyboard for text input.
 Editable: Users can edit the content inside the EditText field.

Q10-What is abstract class ? How is it differ than interface ?


Explain with
example.
An abstract class in Java (and other Object-Oriented languages) is a class that cannot be
instantiated on its own and must be inherited by other classes. It can contain both fully
implemented methods (concrete methods) and abstract methods (methods without
implementation). Abstract classes allow you to define common behavior and enforce that
subclasses implement certain methods.

Key Features:

1. Abstract Methods: These are methods without implementation. Subclasses must


override these methods.
2. Concrete Methods: Abstract classes can also have methods with complete
implementation.
3. Constructors: Abstract classes can have constructors, which can be called from
subclasses.
4. State (Fields): Abstract classes can have member variables (fields), which can be
inherited and used by subclasses.

What is an Interface?

An interface is a reference type in Java, similar to a class, that can contain only abstract
methods (methods without implementation) and constants (fields that are static and final).
Interfaces are used to represent a contract or capability that can be implemented by any class,
regardless of the class hierarchy.

Key Features:

1. Abstract Methods Only: All methods in an interface are implicitly abstract (though
from Java 8 onward, default and static methods with implementation are allowed).
2. Multiple Inheritance: A class can implement multiple interfaces, enabling multiple
inheritance of type.
3. No Constructors or State: Interfaces cannot have constructors or member variables,
except for static final constants.

Feature Abstract Class Interface


Can have both abstract (no Can only have abstract methods (prior to
Methods body) and concrete (with body) Java 8) or default/static methods (from
methods. Java 8 onward).
Can have member variables Can only have constants (static and final
Fields
(fields), which can be inherited. fields).
Multiple A class can inherit only one
A class can implement multiple interfaces.
Inheritance abstract class.
Constructor Can have constructors. Cannot have constructors.
Access Can have any access modifier Methods are implicitly public (can't have
Modifiers (public, protected, private). private methods).

You might also like