Android Fundamentals

  1. What is Android?
    Android is an open-source operating system based on the Linux kernel, designed primarily for touchscreen mobile devices such as smartphones and tablets. It is developed by Google and the Open Handset Alliance (OHA).
  2. What are the main components of an Android application?
    The main components of an Android application include:

    Activities: Represent a single screen with a user interface.
    Services: Run in the background to perform long-running operations.
    Content Providers: Manage access to a structured set of data.
    Broadcast Receivers: Handle communication between Android OS and applications.
    Intents: Facilitate communication between different components.
  3. What is an Activity?
    An Activity is a single, focused task that a user can do. It is a crucial component of an Android app that represents a single screen with a user interface. Activities facilitate user interaction and are where the UI is drawn.
  4. What is an Intent in Android?
    An Intent is a messaging object used to request an action from another app component. Intents can be used to start an activity, start a service, or deliver a broadcast.
  5. What is the AndroidManifest.xml file?
    The AndroidManifest.xml file contains essential information about the app, such as the app’s package name, components of the app, permissions the app requires, and other metadata. It acts as a bridge between the Android system and the application.
  6. What is a Service in Android?
    A Service is a component that runs in the background to perform long-running operations without providing a user interface. It can perform tasks such as playing music, handling network transactions, or interacting with content providers.
  7. What is a Content Provider in Android?
    A Content Provider manages access to a central repository of data. It provides a way to share data between different applications. Content providers are used to handle and manipulate data stored in databases, files, or over the network.
  8. What is a Broadcast Receiver?
    A Broadcast Receiver is a component that responds to broadcast messages from other applications or from the system. Broadcasts can be used to communicate between the Android system and the app (e.g., to inform about changes in battery status, network connectivity, etc.).
  9. What are the different types of Intents?
    Explicit Intents: Specify the exact activity or component to start.
    Implicit Intents: Do not specify the component. Instead, they declare a general action to perform, allowing the system to determine which component can handle the intent.
  10. What is the lifecycle of an Activity?
    The lifecycle of an Activity consists of the following methods:
    – onCreate()
    – onStart()
    – onResume()
    – onPause()
    – onStop()
    – onDestroy()
    – onRestart()
  11. What is the difference between onCreate() and onStart()?
    onCreate() is called when the activity is first created. It is where you initialize your activity. onStart() is called when the activity becomes visible to the user, but it is not yet ready for user interaction.
  12. What is the role of the Gradle build system in Android?
    The Gradle build system is used to automate and manage the build process in Android development. It compiles the code, manages dependencies, packages the app, and allows for custom build configurations.
  13. What is an APK?
    An APK (Android Package) is the file format used to distribute and install applications on the Android operating system. It contains all the necessary files for the application, including the compiled code, resources, and manifest file.
  14. What is the difference between px, dp, and sp?
    px (pixels): The actual pixels on the screen.
    dp (density-independent pixels): An abstract unit that scales with the screen density.
    sp (scale-independent pixels): Similar to dp but also scales with the user’s font size preference.
  15. What is a View in Android?
    A View is a basic building block of the user interface in Android. It is an object that draws something on the screen that the user can interact with, such as a button, text field, or image.
  16. What is a Fragment in Android?
    A Fragment represents a behavior or a portion of the user interface in an Activity. You can combine multiple fragments in a single activity to build a multi-pane UI and reuse a fragment in multiple activities.
  17. What is the difference between Fragment and Activity?
    Activity: Represents a single screen with a user interface.
    Fragment: Represents a portion of an activity. Fragments can be reused in different activities and allow for a more modular and dynamic UI.
  18. What is an Adapter in Android?
    An Adapter acts as a bridge between an AdapterView and the underlying data for that view. It provides access to the data items and is responsible for creating a view for each item in the data set. Examples include ArrayAdapter, CursorAdapter, and BaseAdapter.
  19. What are the different storage options available in Android?
    Shared Preferences: Store private primitive data in key-value pairs.
    Internal Storage: Store private data on the device memory.
    External Storage: Store public data on the shared external storage.
    SQLite Databases: Store structured data in a private database.
    Network: Store data on the web via network servers.
  20. What is a RecyclerView?
    A RecyclerView is a flexible view for providing a limited window into a large data set. It is an advanced and more flexible version of ListView. It uses a ViewHolder pattern to improve performance and provide a smooth scrolling experience.
  21. What is a ViewHolder in RecyclerView?
    A ViewHolder is a design pattern used in RecyclerView to store a reference to each view within a list item and avoid unnecessary findViewById calls, thus improving performance. It holds the views of the item layout and can be reused when the RecyclerView needs to display different items.
  22. What is the role of the onBindViewHolder() method in RecyclerView?
    The onBindViewHolder() method in RecyclerView binds the data to the views in the ViewHolder. It is called by RecyclerView to display the data at the specified position and should update the contents of the ViewHolder to reflect the item at that position.
  23. What are Loaders in Android?
    Loaders are used to load data asynchronously in an activity or fragment. They are designed to handle long-running operations such as querying a database or loading content from a content provider, thus preventing the UI from freezing.
  24. What is the difference between Service and IntentService?
    Service: Runs in the background to perform long-running operations. It does not have a separate thread by default.
    IntentService: A subclass of Service that handles asynchronous requests (expressed as Intents) on demand. It creates a separate worker thread to handle all the incoming intents sequentially.
  25. What is a PendingIntent?
    A PendingIntent in Android is a token that you give to another application (like the alarm manager, notification manager, or other 3rd party application), which allows that application to execute the predefined code within your app, as if the originating application itself was executing the code.
  26. What are ProGuard and R8 in Android?
    ProGuard: A tool that helps to shrink, obfuscate, and optimize your code. It removes unused code and renames classes, fields, and methods with short names to reduce the size of the app.
    R8: A replacement for ProGuard that performs the same functions but with better performance and more features.
    Note:R8 is enabled by default in Android Gradle Plugin 3.4.0 and higher.
  27. What is the Android Jetpack?
    Android Jetpack is a suite of libraries, tools, and guidance provided by Google to help developers write high-quality apps easier and faster. It includes components like Navigation, LiveData, ViewModel, Room, WorkManager, and many others.
  28. What is LiveData?
    LiveData is a lifecycle-aware data holder class provided by Android Jetpack. It respects the lifecycle of other app components, such as activities, fragments, or services, ensuring that LiveData updates only happen if the UI component is in an active state.
  29. What is ViewModel in Android?
    A ViewModel is a class designed to store and manage UI-related data in a lifecycle-conscious way. It allows data to survive configuration changes such as screen rotations.
  30. What is Room Persistence Library?
    Room is a part of Android Jetpack that provides an abstraction layer over SQLite to allow fluent database access while harnessing the full power of SQLite. It reduces boilerplate code and checks SQL queries at compile time.
  31. What is Data Binding in Android?
    Data Binding is a library that allows you to bind UI components in your layouts to data sources in your app using a declarative format rather than programmatically. It helps in reducing boilerplate code and increases the speed of UI updates.
  32. What are the different launch modes in Android?
    standard: Default mode. A new instance of the activity is created each time.
    singleTop: If an instance of the activity already exists at the top of the stack, a new instance will not be created.
    singleTask: Creates a new task and pushes a new instance to the task, or brings the existing instance to the foreground.
    singleInstance: Creates a new task with a single activity. Any new activities started from here will open in a new task.
  33. What is ADB (Android Debug Bridge)?
    ADB is a command-line tool that allows communication with a device. It facilitates a variety of device actions, such as installing and debugging apps, and provides access to a Unix shell that you can use to run various commands on a device.
  34. What is ANR (Application Not Responding)?
    ANR occurs when the main thread of an application is blocked for too long, causing the app to become unresponsive. This typically happens when long operations, such as network requests or database queries, are performed on the main thread instead of a background thread.
  35. What is the use of the findViewById method?
    The findViewById method is used to find a view that was identified by the ID attribute from the XML layout resource. It returns a View object that can be cast to the appropriate subclass.
  36. What are the different types of context in Android?
    Application Context: Associated with the application lifecycle. It can be used to get information about the application environment and is not tied to the lifecycle of any single component.
    Activity Context: Tied to the lifecycle of an activity. It is used for operations related to the activity, such as layout inflation or launching other activities.
  37. What is the difference between ListView and RecyclerView?
    ListView: Simpler and older, does not support ViewHolder pattern by default, less flexible.
    RecyclerView: More advanced, supports ViewHolder pattern, more flexible with LayoutManagers, and supports animations and custom decorations.
  38. What is a Handler in Android?
    A Handler is used to send and process Message and Runnable objects associated with a thread’s MessageQueue. Handlers allow you to perform background operations and update the UI thread from the background.
  39. What is the use of the Looper class in Android?
    The Looper class is used to run a message loop for a thread. It processes messages and runnables queued by a Handler. Each thread can have one Looper that controls the message queue for that thread.
    • Handler posts Message or Runnable to Message Queue.
    • Looper retrieves Message or Runnable from Message Queue.
    • Looper processes Message or executes Runnable.
  40. What is Retrofit?
    Retrofit is a type-safe HTTP client for Android and Java developed by Square, which simplifies web service interactions by turning HTTP API calls into declarative Java interfaces. It ensures type safety by performing compile-time checks on request and response types, reducing runtime errors. Retrofit supports various converters (like Gson and Moshi) for parsing responses and offers both synchronous and asynchronous request handling. Additionally, it provides interceptors for customizing requests, such as adding headers or logging.
  41. What is the purpose of the @Override annotation?
    The @Override annotation indicates that the child class method is overriding a method of its superclass. It is used for clarity and to prevent errors such as typos or mismatched method signatures.
  42. What are the different types of broadcasts in Android?
    Normal Broadcasts: Delivered to all receivers in an unspecified order. Example: ACTION_TIMEZONE_CHANGED
    Ordered Broadcasts: Delivered to one receiver at a time, with each receiver able to propagate or abort the broadcast. Example: ACTION_BATTERY_LOW
    Sticky Broadcasts: Persist after being sent and can be received by any receiver that registers for them. Example: ACTION_BATTERY_CHANGED
    Local Broadcasts:These are broadcasts that are sent and received within the same application. They are more efficient and secure as they do not cross application boundaries. Example: An internal broadcast to update UI components when data is downloaded.
  43. What is broadcast recievers and how to use?
    BroadcastReceiver is used to respond to broadcast messages from other applications or from the system. Broadcasts can be used to inform about changes in battery status, network connectivity, etc.
    We can use in two ways–
    Static:
    • Registered in the manifest file.
    • Always active, even when the app is not running, but subject to background execution limits on Android 8.0 (Oreo) or later.
    Dynamic:
    • Registered and unregistered at runtime within an activity or service.
    • Active only during the lifecycle of the component that registered them, providing flexibility for handling broadcasts as needed.
  44. What is the role of the Application class in Android?
    The Application class in Android is the base class within an Android app that contains all other components such as activities and services. It is instantiated before any other class when the process for the application is created.
  45. What are ANR (Application Not Responding) dialogs and how can you avoid them?
    ANR dialogs appear when the main thread of an app is blocked for too long, typically for more than 5 seconds. To avoid ANRs, avoid long-running operations on the main thread, use background threads or AsyncTask, and optimize your code for better performance.
  46. What is a Parcel in Android?
    A Parcel is a container for a message that can be sent through an IBinder. It is a way to serialize data in Android for IPC (Inter-Process Communication). Unlike traditional serialization, Parcel is not intended for storage but for high-performance IPC.
  47. What is a Binder in Android?
    A Binder is a core part of Android’s IPC mechanism. It is used to manage the communication between different components of the system, such as between activities and services, or between different applications.
  48. What is an AsyncTask?
    AsyncTask is a class that allows you to perform background operations and publish results on the UI thread without having to manipulate threads and handlers directly. It simplifies the execution of background tasks and updating the UI.
  49. What is the difference between View.GONE and View.INVISIBLE?
    View.GONE: The view is hidden and does not take up any space in the layout.
    View.INVISIBLE: The view is hidden but still takes up space in the layout.
  50. What is the Android Architecture Components?
    Android Architecture Components are a collection of libraries that help you design robust, testable, and maintainable apps. They include Lifecycle, LiveData, ViewModel, Room, WorkManager, and Navigation.
  51. What is Dagger in Android?
    Dagger is a fully static, compile-time dependency injection framework for Java and Android. It helps in managing dependencies, making the code more modular, and easier to test.
  52. What are the different types of notifications in Android?
    Simple Notifications: Basic notifications with a title and content.
    Expandable Notifications: Notifications that can expand to show more content.
    Action Notifications: Notifications with action buttons that perform tasks.
    Custom Notifications: Notifications with custom layouts.
  53. What is AndroidX?
    AndroidX is a major improvement to the original Android Support Library. It provides backward compatibility and new features for older Android versions. All libraries in AndroidX live in a consistent namespace starting with androidx. and provide better package structure.
  54. What is the use of the BuildConfig class in Android?
    The BuildConfig class is automatically generated by the build system and contains static fields like DEBUG, APPLICATION_ID, BUILD_TYPE, and VERSION_CODE. It is used to differentiate between build types and flavors.
  55. What is the difference between LinearLayout, RelativeLayout, and ConstraintLayout?
    LinearLayout: Arranges its children in a single row or column.
    RelativeLayout: Arranges its children relative to each other or to the parent.
    ConstraintLayout: Provides a more flexible way of positioning and sizing views by using constraints.
  56. What is the role of setContentView in Android?
    The setContentView method is used to set the activity’s content layout. It defines which layout XML file should be used for the activity’s UI.
  57. What is a SharedPreference in Android?
    SharedPreference is an interface used for accessing and modifying preference data. It provides a simple way to store private primitive data in key-value pairs.
  58. What is Android Support Library?
    The Android Support Library is a set of code libraries that provide backward-compatible versions of Android framework APIs and additional features. It allows developers to use newer APIs on older Android versions.
  59. What is the use of ContentValues in Android?
    ContentValues is used to store a set of values that the ContentResolver can process. It is commonly used when inserting or updating rows in a database.
  60. What is the purpose of ContentResolver in Android?
    ContentResolver is used to interact with the content providers. It provides methods to perform CRUD (Create, Read, Update, Delete) operations on the data managed by content providers.
  61. What is the difference between startService() and bindService()?
    startService(): Starts a service and allows it to run indefinitely. The service is started using startService() and can stop itself by calling stopSelf().
    bindService(): Binds a client to a service. The service runs as long as at least one client is bound to it. Clients can communicate with the service through the IBinder interface.
  62. What is Parcelable and how does it differ from Serializable?
    Parcelable is an Android-specific interface for serialization. It is faster than Java’s Serializable because it avoids reflection and is optimized for Android. Parcelable is used to pass data between activities using Intent.
  63. What is the use of the Intent.FLAG_ACTIVITY_NEW_TASK flag?
    The Intent.FLAG_ACTIVITY_NEW_TASK flag starts the activity in a new task. If the activity already exists in a separate task, it is brought to the front.
  64. What is WorkManager in Android?
    WorkManager is a library in Android Jetpack that manages background tasks that need guaranteed execution, respecting constraints like device charging status, network availability, and scheduled times. It provides a simplified, flexible API to execute one-time or periodic tasks that need to run reliably, even if the app is closed or the device restarts. WorkManager chooses the most appropriate way to schedule tasks based on the device’s API level and the app’s requirements, utilizing JobScheduler, Firebase JobDispatcher, or AlarmManager internally.
  65. What is the difference between SharedPreferences and SQLite?
    SharedPreferences: Stores private, primitive data in key-value pairs. Suitable for storing simple data types.
    SQLite: A database used to store structured data. Suitable for complex data storage needs.
  66. What is the MVP pattern in Android?
    MVP stands for Model-View-Presenter. It is a design pattern used to separate the presentation layer from the business logic. The Model represents the data and business logic, the View displays the data and handles user interactions, and the Presenter acts as a middleman between the Model and View.
  67. What is MVVM pattern in Android?
    MVVM stands for Model-View-ViewModel. It is a design pattern used to separate the UI logic from the business logic. The Model represents the data and business logic, the View displays the data, and the ViewModel holds the UI logic and data for the View.
  68. What is Kotlin and why is it used for Android development?
    Kotlin is a statically typed programming language developed by JetBrains. It is fully interoperable with Java and provides modern language features such as null safety, extension functions, and coroutines. It is officially supported for Android development.
  69. What is Jetpack Compose?
    Jetpack Compose is a modern toolkit for building native Android UIs. It simplifies and accelerates UI development on Android with less code, powerful tools, and intuitive Kotlin APIs.
  70. What is Navigation Component in Android?
    The Navigation Component is part of Android Jetpack. It simplifies navigation and allows you to handle everything needed for in-app navigation, from simple button clicks to more complex patterns, such as app bars and navigation drawers.
  71. What is Paging in Android?
    Paging is a library in Android Jetpack that helps you load and display large data sets efficiently, providing a better user experience by loading data gradually and reducing memory usage.
  72. What is Hilt in Android?
    Hilt is a dependency injection library for Android that reduces the boilerplate of doing manual dependency injection in your project. It is built on top of Dagger and provides a standard way to incorporate Dagger dependency injection into an Android application.
  73. What is the difference between HandlerThread and AsyncTask?
    HandlerThread: A background thread with a Looper. It allows you to perform background operations and handle messages.
    AsyncTask: A class that allows you to perform background operations and publish results on the UI thread without manipulating threads and handlers directly.
  74. What is ViewBinding in Android?
    ViewBinding is a feature that allows you to more easily write code that interacts with views. Once enabled, it generates a binding class for each XML layout file present in that module. In most cases, it replaces findViewById.
  75. What is DataStore in Android?
    DataStore is a Jetpack library that provides a robust data storage solution. It is a replacement for SharedPreferences and provides two different implementations: Preferences DataStore and Proto DataStore.
  76. What are Scopes in Kotlin Coroutines?
    Scopes in Kotlin Coroutines define the lifecycle of coroutines. They manage the lifecycle of coroutines, ensuring that they are canceled when they are no longer needed. Common scopes include GlobalScope, CoroutineScope, and ViewModelScope.
  77. What is EncryptedSharedPreferences?
    EncryptedSharedPreferences in Android Jetpack Security library provides a secure way to store encrypted key-value pairs in SharedPreferences. It uses AES encryption with Android Keystore integration, ensuring data confidentiality even if the device is compromised. It simplifies data protection for sensitive information such as authentication tokens and API keys.
    // Initialize EncryptedSharedPreferences
    SharedPreferences sharedPreferences = EncryptedSharedPreferences.create(
            context,
            "my_secure_prefs",  // File name for encrypted SharedPreferences
            masterKeyAlias,     // Master key alias for encryption keys in Android Keystore
            EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,   // Key encryption scheme
            EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM  // Value encryption scheme
    );
    
    // Usage: store and retrieve encrypted data
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString("key", "value");
    editor.apply();
    
    // Retrieve encrypted data
    String retrievedValue = sharedPreferences.getString("key", defaultValue);
    
  78. What is Android Keystore?
    The Android Keystore is a secure system provided by Android for storing cryptographic keys. It safeguards keys from extraction and unauthorized use, leveraging hardware-backed security if available. Developers can use the Keystore to generate, import, and manage keys for encryption, decryption, and other cryptographic operations, ensuring strong protection for sensitive data within Android applications.

Leave a comment

Your email address will not be published. Required fields are marked *