Friday, May 30, 2025

Android Kotlin Interview Questions for Freshers Part 1

 

Here are 50 important interview questions and answers for a fresher Android developer role, covering fundamentals of Android, Java/Kotlin, and some common development practices.


1. What is Android?

Android is an open-source operating system developed by Google, primarily designed for touchscreen mobile devices such as smartphones and tablets. It is based on the Linux kernel and provides a rich application framework that allows developers to create innovative apps. Android is widely used due to its flexibility, large user base, and support for multiple hardware configurations. It supports a vast ecosystem of apps available via the Google Play Store and other app markets.


2. What are the main components of Android?

Android applications are made up of four essential components:

  • Activities: Represent a single screen with a user interface where users interact with the app.
  • Services: Background components that perform long-running operations without a user interface (e.g., playing music).
  • Broadcast Receivers: Components that respond to system-wide broadcast announcements (like battery low, network change).
  • Content Providers: Manage shared application data and enable data sharing between applications.

These components work together and are declared in the app’s manifest file.


3. What is an Activity in Android?

An Activity represents one screen in an app, similar to a window or page in a desktop or web app. It contains the UI elements the user interacts with. When an app starts, it usually begins with a main Activity. Activities are responsible for managing the UI, responding to user inputs, and handling transitions between screens.

Each Activity has a lifecycle, which includes various states like creation, start, resume, pause, stop, and destroy. Developers override lifecycle methods (like onCreate(), onResume()) to handle what happens during those states.


4. What is a Service in Android?

A Service is a component that performs operations in the background without a user interface. It is used when you want to run long-running tasks independent of user interaction, such as playing music, downloading files, or fetching data from a network.

Services can run indefinitely even if the user switches to another app, unless the system kills them due to resource constraints. There are different types of services: started services, bound services, and foreground services, each serving different purposes.


5. What is a Content Provider?

A Content Provider manages access to a structured set of data. It encapsulates data and provides mechanisms for other apps to query or modify it securely. Content Providers are commonly used to share data between apps (e.g., contacts, media).

They provide standard interfaces like query, insert, update, and delete to interact with the data and help maintain data integrity and permissions.


6. What is the AndroidManifest.xml file?

The AndroidManifest.xml is a critical file located at the root of every Android project. It acts as a roadmap that tells the Android system about the app’s components (activities, services, broadcast receivers, content providers), required permissions (internet, camera), app features, and hardware requirements.

Without this file, the system doesn’t know how to launch or manage the app components.


7. What is an Intent?

An Intent is a messaging object that facilitates communication between components, either within the same app or between different apps. Intents can be used to start an Activity, start a Service, or deliver a broadcast.

There are two types:

  • Explicit Intent: Specifies the exact component to launch (used within the same app).
  • Implicit Intent: Declares a general action to perform (like view a webpage or call a number), and the system decides which app/component can handle it.

8. What is the difference between implicit and explicit Intent?

  • Explicit Intent: Directly specifies the target component by class name. For example, navigating from one activity to another within the same app.
  • Implicit Intent: Does not name a specific component but declares a general action to be performed (like sharing text or opening a map). The Android system then finds the best component capable of handling the request.

Example:
Explicit Intent - new Intent(this, DetailActivity.class);
Implicit Intent - new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com"));


9. What is the Activity Lifecycle?

The Activity Lifecycle describes the states an Activity goes through from creation to destruction. Android manages these states via callback methods:

  • onCreate() — Called when the activity is first created; setup UI here.
  • onStart() — Activity is becoming visible.
  • onResume() — Activity comes to the foreground and becomes interactive.
  • onPause() — Another activity is coming into the foreground; this one is partially visible.
  • onStop() — Activity is no longer visible.
  • onDestroy() — Activity is being destroyed.

Understanding this lifecycle helps manage resource usage and save/restore state properly.


10. What is the Fragment Lifecycle?

Fragments are reusable components that represent a portion of UI in an Activity. They have their own lifecycle closely tied to their host Activity.

Important Fragment lifecycle methods:

  • onAttach() — Fragment is attached to the Activity.
  • onCreateView() — Creates and returns the view hierarchy.
  • onActivityCreated() — Activity and fragment views are created.
  • onStart() — Fragment becomes visible.
  • onResume() — Fragment is active and interacting.
  • onPause(), onStop(), onDestroyView(), onDetach() — Fragments are stopped, views destroyed, and finally detached from Activity.

Fragments allow dynamic and flexible UI designs, especially on tablets or large screens.


11. What is a View in Android?

A View is the basic building block of the Android user interface (UI). It represents a rectangular area on the screen and is responsible for drawing and event handling (like clicks or touches). Examples of views include:

  • TextView: Displays text to the user.
  • Button: A clickable button.
  • ImageView: Displays an image.

All UI widgets inherit from the View class. Views can be combined or nested inside ViewGroups to create complex layouts.


12. What is a ViewGroup?

A ViewGroup is a container that holds and organizes multiple child views or other ViewGroups. It defines the layout structure and controls how the child views are positioned and sized on the screen.

Common ViewGroups include:

  • LinearLayout: Arranges children in a single row or column.
  • RelativeLayout: Positions children relative to each other or parent.
  • ConstraintLayout: More flexible and powerful layout allowing complex positioning with constraints.
  • FrameLayout: Simple layout used to block out an area on the screen to display a single item.

13. What is RecyclerView?

RecyclerView is a flexible and efficient widget for displaying large sets of data or lists. Unlike ListView, it enforces the ViewHolder pattern, which improves performance by recycling views that have scrolled off-screen, rather than creating new ones every time.

Features of RecyclerView:

  • Supports different layout managers (linear, grid, staggered grid).
  • Allows animations when items are added or removed.
  • Provides item decorators to customize appearance.

It’s the recommended widget for displaying scrollable lists in modern Android apps.


14. Difference between ListView and RecyclerView?

Aspect

ListView

RecyclerView

View Recycling

Basic recycling but less efficient

Advanced recycling using ViewHolder pattern for better performance

Layout Flexibility

Supports vertical scrolling only

Supports multiple layout managers (vertical, grid, staggered)

Animations

Limited support

Supports default animations and custom ones

Item Decoration

No built-in support

Supports item decorators for dividers and margins

ViewHolder Pattern

Optional (but recommended)

Mandatory, improves performance


15. What is ConstraintLayout?

ConstraintLayout is a powerful ViewGroup introduced to help build complex layouts without deep nesting of views. It allows you to position and size widgets based on constraints to other widgets or the parent container.

Advantages:

  • Reduces view hierarchy depth (better performance).
  • Supports chains, barriers, and guidelines for advanced layouts.
  • Offers a visual editor in Android Studio for easier design.

16. How do you handle button clicks in Android?

Button clicks are handled by attaching an OnClickListener to the Button view:

Example in Java:

java

CopyEdit

Button btn = findViewById(R.id.my_button);

btn.setOnClickListener(new View.OnClickListener() {

    @Override

    public void onClick(View v) {

        // Code to execute when button is clicked

        Toast.makeText(getApplicationContext(), "Button clicked!", Toast.LENGTH_SHORT).show();

    }

});

In Kotlin, it’s simpler:

kotlin

CopyEdit

val btn = findViewById<Button>(R.id.my_button)

btn.setOnClickListener {

    Toast.makeText(this, "Button clicked!", Toast.LENGTH_SHORT).show()

}


17. What is a Toast in Android?

A Toast is a short, non-interactive popup message that informs the user about an operation without blocking their interaction. Toast messages automatically disappear after a short duration.

Example:

java

CopyEdit

Toast.makeText(context, "Hello, this is a Toast!", Toast.LENGTH_SHORT).show();

Use Toasts for quick notifications like “Message sent” or “Settings saved.”


18. What is Snackbar?

A Snackbar is a lightweight feedback widget that appears at the bottom of the screen, similar to Toast but more flexible. It supports an optional action button that users can tap to perform an action (e.g., Undo).

Example in Kotlin:

kotlin

CopyEdit

Snackbar.make(view, "Item deleted", Snackbar.LENGTH_LONG)

    .setAction("UNDO") {

        // Undo deletion code

    }

    .show()

Snackbar is part of the Material Design library and preferred over Toast for interactive messages.


19. What are styles and themes in Android?

  • Style: A collection of attributes that specify the look and format for a single View (e.g., text size, color). Styles help reuse design definitions across multiple widgets.
  • Theme: A style applied to an entire app or Activity, influencing the look of all views and widgets inside it (like colors, fonts, default styles).

Example: A theme might define primary colors, default button style, and background color for the whole app.


20. What is a Dialog?

A Dialog is a small window that prompts the user to make a decision or enter information without leaving the current screen. Common types:

  • AlertDialog: Displays alerts with buttons (e.g., OK, Cancel).
  • ProgressDialog: Shows progress during long operations (deprecated now).
  • Custom Dialog: Allows creating fully customized dialog layouts.

Example of an AlertDialog:

java

CopyEdit

new AlertDialog.Builder(this)

    .setTitle("Delete entry")

    .setMessage("Are you sure you want to delete this?")

    .setPositiveButton("Yes", (dialog, which) -> {

        // Delete action

    })

    .setNegativeButton("No", null)

    .show();


21. What is the difference between Java and Kotlin?

  • Java: A widely used, general-purpose programming language and the traditional language for Android development. It is verbose and requires boilerplate code but has a mature ecosystem.
  • Kotlin: A modern, concise, statically typed programming language officially supported by Google for Android. It reduces boilerplate, adds null safety, extension functions, coroutines for asynchronous programming, and better interoperability with Java. Kotlin code tends to be safer and more readable.

Kotlin compiles to JVM bytecode, so it runs on the same platform as Java.


22. What is a nullable type in Kotlin?

Kotlin distinguishes between nullable and non-nullable types to reduce the chances of NullPointerException (NPE).

  • Non-nullable type: Variables cannot hold null. Example:

kotlin

CopyEdit

var name: String = "John"

  • Nullable type: Variables can hold a null value, denoted by adding ? to the type. Example:

kotlin

CopyEdit

var name: String? = null

When accessing nullable variables, Kotlin forces you to perform null checks or use safe calls (?.) to prevent crashes.


23. What are data classes in Kotlin?

A data class is a special class in Kotlin designed to hold data. It automatically generates useful functions such as equals(), hashCode(), toString(), and copy() based on the properties declared in the primary constructor.

Example:

kotlin

CopyEdit

data class User(val name: String, val age: Int)

Data classes simplify creating models and DTOs (Data Transfer Objects).


24. What is the difference between val and var?

  • val (value): Defines a read-only reference, like a final variable in Java. Once assigned, it cannot be reassigned.
  • var (variable): Defines a mutable variable whose value can be changed.

Example:

kotlin

CopyEdit

val name = "Alice"  // Cannot be reassigned

var age = 25       // Can be reassigned later

Use val by default for immutability and thread safety.


25. What are higher-order functions in Kotlin?

Higher-order functions are functions that take other functions as parameters or return functions. They enable functional programming techniques.

Example:

kotlin

CopyEdit

fun performOperation(x: Int, y: Int, operation: (Int, Int) -> Int): Int {

    return operation(x, y)

}

 

val sum = performOperation(5, 3) { a, b -> a + b }  // sum = 8

They allow concise and reusable code.


No comments:

Post a Comment

Top 30 interview questions

Android Development Interview Q&A (5+ Years Experience) Android Development Fundamentals Q: What are the main Android app components and...