Android Programming Question Bank
Android Programming Question Bank
Broadcast receivers in Android allow applications to register for system or application events. When an event occurs, the system broadcasts it, and the interested applications can respond to these events, such as receiving SMS or battery status changes. Implementation requires registering the receiver in the AndroidManifest.xml and defining the actions it should listen to, or creating the receiver programmatically using Context.registerReceiver().
Applications can monitor changes in phone state through the use of broadcast receivers. The TelephonyManager class allows applications to listen for changes in phone states like call state, cell location or if a network is available. Implementing PhoneStateListener with overridden callback methods is a common approach to detect and respond to these changes, which is essential for apps needing to adapt to varying telephony status .
The Dalvik Virtual Machine (DVM) is optimized for Android devices, designed to run applications efficiently on devices with limited memory and CPU. Unlike the JVM, DVM uses the dex (Dalvik Executable) format, which is more compact and suited for low-memory environments. Dalvik also facilitates compilation of classes once and caching the results for efficient execution. This differs from JVM's approach, which emphasizes cross-platform functionality over performance on resource-constrained devices .
Explicit intents specify the component to start by name, used mainly to start a specific activity within the same app. Implicit intents declare an action and allow other applications to handle them, typically used for actions like share or view, where the specific app handling the intent can vary .
Android's Geocoder class provides geocoding and reverse geocoding functionalities, allowing the translation of addresses into geographic coordinates and vice versa using Android-specific APIs without needing third-party services. Traditional geocoding services might offer more features and higher accuracy but require internet access or additional libraries, whereas Geocoder relies on available Android libraries, making it more integrated but less flexible and often reliant on device resources .
The Android activity life cycle consists of several states: onCreate(), onStart(), onResume(), onPause(), onStop(), and onDestroy(). These states allow developers to manage the state of an activity as it moves through its lifecycle. Understanding this life cycle is crucial because it helps in resource management, ensuring efficient memory usage, and correctly handling user input and UI display. It also aids in saving and restoring the activity state during configuration changes, such as screen rotations .
Advantages of SQLite include its serverless architecture and simplicity, which require no configuration, and it's lightweight, resulting in minimal memory footprint. It is ACID-compliant and supports most SQL standards, making it reliable for local data storage. However, disadvantages include limited support for concurrent writes, which could be a bottleneck for high-throughput applications, and a cap on the size of the database limited by device storage space .
Android architecture consists of five major components: the Linux kernel, libraries, Android Runtime (ART), application framework, and applications. The Linux kernel manages core system services and hardware abstraction. Libraries, sitting above the kernel, include system utilities, and the ART runs Java bytecode in a more optimized manner than its predecessor DVM. The application framework provides APIs for app components, while applications are at the top layer, interacting with the lower layers to perform various functions through these APIs and services .
Managing different screen sizes and orientations is critical to ensure a consistent and user-friendly interface across diverse Android devices. It involves using responsive design techniques, such as flexible layouts, resource qualifiers, and dynamic adjustment of UI elements. This ensures that applications provide an optimal user experience, maintaining usability and aesthetics, regardless of device type or screen configuration .
AlarmManager is used in Android to schedule tasks to run at a future time. It can set alarms that trigger an event or start a service at a specified time, even if the device is asleep. However, its use is more suited for lightweight and non-repetitive tasks as it is not precise due to Android's power optimization practices. It may also not trigger exact timings due to system adjustments for battery conservation, requiring careful consideration of its limitations .