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

Introduction to Android and Kotlin

The document contains a series of questions and answers related to Android development, focusing on programming languages, components, and best practices. Key topics include the use of Kotlin, the role of Activities and Intents, and the Android lifecycle. It also covers UI elements, data handling, and testing methodologies in Android applications.

Uploaded by

i.shelyyy
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Introduction to Android and Kotlin

The document contains a series of questions and answers related to Android development, focusing on programming languages, components, and best practices. Key topics include the use of Kotlin, the role of Activities and Intents, and the Android lifecycle. It also covers UI elements, data handling, and testing methodologies in Android applications.

Uploaded by

i.shelyyy
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 16

Which of the following is the primary programming language for Android development?

A. Swift
B. Java
C. Kotlin
D. Python
ANSWER: C

What is the main advantage of using **Kotlin** over **Java** for Android
development?
A. Kotlin is more complex and harder to learn
B. Kotlin is more concise and reduces boilerplate code
C. Java is faster than Kotlin for Android development
D. Java integrates better with Android Studio
ANSWER: B

In Android development, what is the role of an **Activity**?


A. It is a UI element for displaying information on a screen
B. It manages the background processes of the app
C. It represents a single screen in an app where user interaction occurs
D. It handles the app’s network connections
ANSWER: C

What is **Android Studio** used for?


A. Designing Android app graphics
B. Writing and debugging Kotlin code for Android apps
C. Managing Android app databases
D. Publishing Android apps to the Google Play Store
ANSWER: B

Which Android component is responsible for responding to user inputs like button
clicks?
A. Intent
B. Activity
C. Service
D. View
ANSWER: D

In Kotlin, what is the purpose of the `val` keyword?


A. It declares a variable that can be reassigned
B. It declares a variable that cannot be reassigned (immutable)
C. It defines a function in the Kotlin program
D. It imports a library in Kotlin
ANSWER: B

What is the default visibility of a class in Kotlin?


A. Public
B. Private
C. Protected
D. Internal
ANSWER: A

What is an **Intent** in Android development?


A. A visual element used for user input
B. A mechanism for launching a new activity or communicating between components
C. A class used for database management
D. A user interface design tool in Android Studio
ANSWER: B

How do you declare a function in Kotlin that takes two parameters and returns an
integer?
A. `fun add(a: Int, b: Int) -> Int { return a + b }`
B. `fun add(a: Int, b: Int): Int { return a + b }`
C. `function add(a: Int, b: Int): Int { return a + b }`
D. `def add(a: Int, b: Int): Int { return a + b }`
ANSWER: B

Which file in an Android project contains information about the app such as
permissions and components?
A. `MainActivity.kt`
B. `build.gradle`
C. `AndroidManifest.xml`
D. `strings.xml`
ANSWER: C

What is the primary advantage of using **Kotlin** for Android development?


A. Kotlin has more features than Java
B. Kotlin is a more concise and expressive language compared to Java
C. Kotlin does not require any Android Studio support
D. Kotlin is only supported on the Android platform
ANSWER: B

How do you declare a **mutable variable** in Kotlin?


A. `var x = 10`
B. `val x = 10`
C. `const x = 10`
D. `let x = 10`
ANSWER: A

What is the purpose of the `val` keyword in Kotlin?


A. It declares a variable that can be reassigned
B. It declares a function in the Kotlin program
C. It declares a constant variable that cannot be reassigned
D. It creates a loop in Kotlin
ANSWER: C

In Kotlin, what is the result of the expression `5 / 2`?


A. `2.5`
B. `2.0`
C. `3`
D. `2`
ANSWER: D

How do you define a **nullable type** in Kotlin?


A. `String?`
B. `String!!`
C. `String&`
D. `String#`
ANSWER: A

Which of the following statements about **functions** in Kotlin is true?


A. Functions must always have a return type
B. Kotlin functions can return multiple values
C. Functions in Kotlin can have default arguments
D. Kotlin does not support functions as values
ANSWER: C

What does the `when` keyword in Kotlin do?


A. It is used to create loops
B. It is used to declare a function
C. It is used for conditional expressions, similar to a switch statement in other
languages
D. It defines a class in Kotlin
ANSWER: C

In Kotlin, how would you check if a variable `x` is equal to `null`?


A. `if (x == null)`
B. `if (x != null)`
C. `if (x is null)`
D. `if (x == nothing)`
ANSWER: A

Which of the following statements about **Kotlin classes** is true?


A. Classes in Kotlin cannot have constructors
B. Kotlin uses the `class` keyword to define a class
C. Classes in Kotlin must be abstract by default
D. Kotlin does not support inheritance
ANSWER: B

How do you define a **data class** in Kotlin?


A. `data class Person(val name: String, val age: Int)`
B. `class data Person(val name: String, val age: Int)`
C. `data Person class(val name: String, val age: Int)`
D. `class Person(data val name: String, val age: Int)`
ANSWER: A

What is the default directory for storing **Kotlin source files** in an Android
project?
A. `src/main/kotlin`
B. `src/main/res`
C. `src/main/assets`
D. `src/main/java`
ANSWER: A

Which directory in an Android project contains **UI resources** like layouts,


images, and strings?
A. `src/main/res`
B. `src/main/java`
C. `src/main/assets`
D. `src/main/kotlin`
ANSWER: A

What file in an Android project contains metadata about the application, such as
permissions and components?
A. `AndroidManifest.xml`
B. `build.gradle`
C. `MainActivity.kt`
D. `strings.xml`
ANSWER: A

Which layout manager is commonly used for creating flexible and responsive user
interfaces in Android?
A. `LinearLayout`
B. `RelativeLayout`
C. `ConstraintLayout`
D. `FrameLayout`
ANSWER: C
How do you define a **Button** in an XML layout file for an Android application?
A. `<Button type="submit">Click Me</Button>`
B. `<Button android:text="Click Me" />`
C. `<Button>Click Me</Button>`
D. `<Button name="Click Me"/>`
ANSWER: B

In Android, what is the purpose of the **`res/values/strings.xml`** file?


A. To store images for the app
B. To store application settings
C. To store all the text strings used in the app
D. To define layout dimensions
ANSWER: C

Which of the following is used to handle user input in a **TextView** widget in


Android?
A. `android:text`
B. `android:editable`
C. `android:onClick`
D. `android:inputType`
ANSWER: D

What is the purpose of the **`onCreate()`** method in an Android **Activity**?


A. To initialize the user interface and set the layout
B. To handle user input events
C. To destroy the current activity
D. To handle background services
ANSWER: A

Which Android component is responsible for providing **navigation** between


different screens (activities) in an app?
A. **Intent**
B. **Service**
C. **BroadcastReceiver**
D. **ContentProvider**
ANSWER: A

How do you define a **ConstraintLayout** in XML for an Android activity?


A. `<ConstraintLayout>...</ConstraintLayout>`
B. `<RelativeLayout>...</RelativeLayout>`
C. `<LinearLayout>...</LinearLayout>`
D. `<FrameLayout>...</FrameLayout>`
ANSWER: A

What is the first method called in the **Activity lifecycle** when an Android app
is launched?
A. `onPause()`
B. `onCreate()`
C. `onStart()`
D. `onResume()`
ANSWER: B

Which method is called when an activity is no longer visible to the user but is
still in memory?
A. `onCreate()`
B. `onStop()`
C. `onPause()`
D. `onResume()`
ANSWER: B
In the **Activity lifecycle**, which method is used to restart an activity after it
has been stopped?
A. `onRestart()`
B. `onResume()`
C. `onStart()`
D. `onCreate()`
ANSWER: A

What happens when the **onPause()** method is called in the **Activity lifecycle**?
A. The activity is destroyed
B. The activity is resumed immediately
C. The activity is paused but still in memory
D. The activity is stopped and removed from memory
ANSWER: C

Which method in the **Activity lifecycle** is called when the user returns to an
activity after it has been paused or stopped?
A. `onRestart()`
B. `onResume()`
C. `onCreate()`
D. `onStart()`
ANSWER: B

Which of the following is TRUE about **user interaction** in Android apps?


A. The **Button** widget is used to display text in the user interface
B. **TextView** is used for user input and capturing text data
C. **EditText** allows users to input text into the app
D. **Button** is used only to display a message without user interaction
ANSWER: C

How can an Android developer handle a **button click event** in Kotlin?


A. By overriding the `onClick()` method in the `Activity` class
B. By using `setOnClickListener()` method on the `Button` object
C. By using the `Button()` constructor method
D. By calling the `onTouch()` method directly
ANSWER: B

What is the primary purpose of the **onCreate()** method in the **Activity


lifecycle**?
A. To pause the activity when the app goes into the background
B. To initialize the activity and set up the user interface
C. To clean up resources when the activity is stopped
D. To manage background services
ANSWER: B

Which Android component allows **passing data between activities** using


**Intents**?
A. **TextView**
B. **SharedPreferences**
C. **Button**
D. **Intent**
ANSWER: D

In Android, which method is called when an activity is **completely finished and


removed from the activity stack**?
A. `onStop()`
B. `onDestroy()`
C. `onPause()`
D. `onRestart()`
ANSWER: B

What is an **Intent** in Android used for?


A. Launching a new thread in the app
B. Starting a new activity or communicating between components of an app
C. Managing background services
D. Storing user data locally
ANSWER: B

Which type of **Intent** allows you to start an activity within the same
application?
A. Implicit Intent
B. Explicit Intent
C. Broadcast Intent
D. Pending Intent
ANSWER: B

What is the purpose of an **Implicit Intent**?


A. To pass data between two activities within the same app
B. To start an activity from another app or service without explicitly specifying
the activity class
C. To execute a background task asynchronously
D. To create a new instance of a service in the app
ANSWER: B

How do you pass **data** between activities using an Intent in Kotlin?


A. By calling `startActivityForResult()` method
B. By using the `Intent.putExtra()` method to attach key-value pairs
C. By directly assigning values to the activity’s instance variables
D. By calling `Intent.create()` method
ANSWER: B

In Android, what is the function of the `startActivity()` method?


A. It retrieves the data passed to the current activity
B. It starts a new activity defined by an **Intent**
C. It stops an activity from running
D. It pauses the current activity and runs it in the background
ANSWER: B

When navigating between activities, which **Intent flag** should be used to ensure
that a new instance of an activity is created?
A. `Intent.FLAG_ACTIVITY_CLEAR_TOP`
B. `Intent.FLAG_ACTIVITY_NEW_TASK`
C. `Intent.FLAG_ACTIVITY_SINGLE_TOP`
D. `Intent.FLAG_ACTIVITY_CLEAR_TASK`
ANSWER: B

How can you **navigate** between fragments within the same activity in Android?
A. Using an **Intent** to start the fragment
B. Using the `FragmentTransaction` object to replace or add fragments
C. By invoking the fragment’s `onCreate()` method directly
D. Using the `Activity.startActivity()` method
ANSWER: B

What is the purpose of the `onActivityResult()` method in Android?


A. To handle data that is returned from a launched activity
B. To navigate to the next activity
C. To save the instance state of an activity
D. To start an intent with a pending result
ANSWER: A

Which Android component is responsible for handling **navigation between


activities** and **passing data** using **Intents**?
A. **Service**
B. **Activity**
C. **BroadcastReceiver**
D. **ContentProvider**
ANSWER: B

In Android, how do you specify that an **Intent** should open a **specific


activity** from another app?
A. By defining an implicit intent with an action
B. By using the package name in the Intent to specify the target app
C. By declaring the activity in the `strings.xml` file
D. By using the `setTargetActivity()` method
ANSWER: B

Which of the following is the main advantage of using **RecyclerView** in Android?


A. It automatically handles the layout of all elements in a list
B. It allows for efficient display and management of large sets of data in a
scrollable list
C. It can only display text data
D. It is only used for displaying images
ANSWER: B

In **RecyclerView**, what does the **Adapter** do?


A. It provides a UI for the RecyclerView
B. It creates new views for each item in the RecyclerView
C. It binds data to the RecyclerView's view elements
D. It manages the layout of the RecyclerView itself
ANSWER: C

In the **Fragment lifecycle**, which method is called when a fragment is no longer


visible but still in memory?
A. `onPause()`
B. `onStop()`
C. `onDestroy()`
D. `onCreate()`
ANSWER: B

How do you add a **Fragment** to an **Activity** in Android?


A. By using `FragmentTransaction.add()`
B. By calling the `addFragment()` method in the activity
C. By invoking the `Fragment.replace()` method
D. By including the fragment in the `activity_main.xml` layout file
ANSWER: A

What is the primary purpose of **debugging** in Android development?


A. To remove unused variables in the code
B. To improve the appearance of the user interface
C. To identify and fix runtime errors and bugs in the application
D. To speed up the app's performance
ANSWER: C

In Android Studio, what is the **Logcat** used for?


A. To manage databases in the app
B. To simulate user input in an app
C. To display debug messages, errors, and system logs during app development
D. To manage and test app notifications
ANSWER: C

How can you handle **errors** in Kotlin for Android applications?


A. By using `try-catch` blocks to catch exceptions
B. By using `onError()` callback methods in the UI
C. By ignoring all exceptions and continuing app execution
D. By placing all code in the `onCreate()` method
ANSWER: A

Which of the following is a common testing method used for Android apps to ensure
the app works correctly on different devices and configurations?
A. **Unit testing**
B. **UI testing**
C. **Performance testing**
D. All of the above
ANSWER: D

Which tool in Android Studio is used to generate an APK file for deployment on
devices or publishing to the Google Play Store?
A. **Emulator**
B. **Gradle**
C. **Logcat**
D. **Build System**
ANSWER: B

Which Android testing framework allows you to write tests for user interactions and
simulate button clicks, screen touches, and other UI actions?
A. **JUnit**
B. **Espresso**
C. **Mockito**
D. **Robolectric**
ANSWER: B

What is the official language for Android development as of 2024?


A. Java
B. Python
C. Kotlin
D. C++
ANSWER: C

Which tool is primarily used to build Android applications?


A. Eclipse
B. Xcode
C. Android Studio
D. Visual Studio Code
ANSWER: C

Which Android component manages the user interface (UI)?


A. Service
B. Activity
C. BroadcastReceiver
D. ContentProvider
ANSWER: B

What does APK stand for in Android development?


A. Android Package
B. Android Programming Kit
C. Application Programming Kit
D. Android Platform Kit
ANSWER: A

Which Android component is used to handle background tasks and services?


A. Activity
B. Service
C. Intent
D. BroadcastReceiver
ANSWER: B

Which file extension is used for Kotlin source files in Android development?
A. .java
B. .kt
C. .xml
D. .class
ANSWER: B

Which of the following is a feature introduced by Kotlin in Android development?


A. Null safety
B. Memory management
C. Multithreading
D. None of the above
ANSWER: A

Which of the following is the primary purpose of the Kotlin data class?
A. To store data without methods
B. To store and manipulate data
C. To store variables
D. To simplify code
ANSWER: B

Which function in Kotlin is used to create a default value for variables that might
be null?
A. let
B. ?:
C. if-null
D. default
ANSWER: B

In Kotlin, which of these is the correct way to declare an immutable variable?


A. var
B. val
C. const
D. let
ANSWER: B

What is the primary purpose of the onCreate() method in an Activity?


A. To destroy the Activity
B. To initialize the UI elements
C. To bind services
D. To handle background tasks
ANSWER: B

Which keyword in Kotlin is used to declare a class that can be inherited by other
classes?
A. open
B. inherit
C. base
D. extend
ANSWER: A

Which of the following is a valid way to create a function in Kotlin?


A. fun myFunction() {}
B. def myFunction() {}
C. function myFunction() {}
D. create myFunction() {}
ANSWER: A

What does the val keyword in Kotlin represent?


A. A variable that can be modified
B. A constant that cannot be changed
C. A nullable reference
D. A pointer to an object
ANSWER: B

Which data type in Kotlin is used for variables that can hold either a value or
null?
A. String
B. Int
C. Nullable type
D. Char
ANSWER: C

Which method is used to convert a string to an integer in Kotlin?


A. toInt()
B. convertInt()
C. intValue()
D. parseInt()
ANSWER: A

Which of the following is a valid way to define a class in Kotlin?


A. class MyClass() {}
B. class MyClass {}
C. class MyClass[] {}
D. class MyClass() [] {}
ANSWER: B

How can you handle nullable types in Kotlin?


A. By using the ? operator
B. By using the !! operator
C. By casting the variable to non-null
D. Both A and B
ANSWER: D

What is the function of try and catch in Kotlin?


A. To handle null pointer exceptions
B. To handle exceptions or errors in code
C. To catch and ignore errors
D. To throw errors manually
ANSWER: B

What is the result of the following Kotlin code: val result = 5 / 0?


A. It throws a ArithmeticException
B. It returns zero
C. It returns Infinity
D. It is a valid operation
ANSWER: A

In Kotlin, how do you make a class implement an interface?


A. By using the implement keyword
B. By using the extends keyword
C. By using the interface keyword
D. By using the : symbol
ANSWER: D

Which Kotlin function can be used to check if a value is null?


A. isNull()
B. checkNull()
C. nullCheck()
D. ?.
ANSWER: D

What does the when expression in Kotlin replace?


A. switch-case statements
B. if-else statements
C. function definitions
D. variable declarations
ANSWER: A

What is the correct way to declare an array in Kotlin?


A. val numbers = Array[5]
B. val numbers = arrayOf(1, 2, 3, 4, 5)
C. val numbers = [1, 2, 3, 4, 5]
D. val numbers = list(1, 2, 3, 4, 5)
ANSWER: B

What is a Fragment in Android development?


A. A small part of a UI within an Activity
B. A separate Activity for handling background tasks
C. A shared service between apps
D. A static UI component
ANSWER: A

Which method in a Fragment is used to initialize its view?


A. onStart()
B. onCreateView()
C. onAttach()
D. onViewCreated()
ANSWER: B

What is the primary purpose of using Fragments in Android?


A. To manage UI components for Activities
B. To enable communication between Activities
C. To break down large UI into reusable parts
D. To handle background tasks
ANSWER: C

Which lifecycle method of a Fragment is called when it is attached to an Activity?


A. onPause()
B. onDetach()
C. onAttach()
D. onCreate()
ANSWER: C

Which of the following is NOT true about Fragments?


A. They can be dynamically added or removed from an Activity
B. They can be used to display user interfaces
C. They can exist independently of Activities
D. They must always be used within an Activity
ANSWER: C

In Android, which of the following is used to add or replace a Fragment?


A. FragmentManager
B. FragmentActivity
C. FragmentView
D. FragmentContainer
ANSWER: A

Which method in Android is used to replace a Fragment with another Fragment in the
UI?
A. replaceFragment()
B. addFragment()
C. beginTransaction()
D. setFragment()
ANSWER: C

What method do you use to save the state of a Fragment before it is destroyed?
A. onSaveInstanceState()
B. onPause()
C. onStop()
D. onDestroy()
ANSWER: A

Which tool is used to log debug information in Android?


A. Android Logcat
B. Android Emulator
C. Android Profiler
D. Android Debugger
ANSWER: A

Which method is used to print debug information in Android?


A. Log.d()
B. Debug.print()
C. System.out.println()
D. Debug.log()
ANSWER: A

What happens if you call a function on a null object in Kotlin?


A. It throws a NullPointerException
B. It returns null
C. It returns a default value
D. It compiles without errors
ANSWER: A

Which Kotlin operator is used to safely call a method on a nullable object?


A. ?
B. !!
C. !!
D. &&
ANSWER: A

In Android, which of the following is an appropriate way to handle errors during an


API call?
A. Use try-catch blocks
B. Check for exceptions and log them
C. Use assert() method
D. Use println() for errors
ANSWER: A

In Android, what is a common debugging technique for inspecting app performance?


A. Using Profiler
B. Setting breakpoints
C. Using Logcat
D. All of the above
ANSWER: D

What Android tool can you use to track app crashes and exceptions in production?
A. Android Profiler
B. Firebase Crashlytics
C. Android Emulator
D. Android Logcat
ANSWER: B

Which of the following is used for unit testing in Kotlin?


A. JUnit
B. Mockito
C. Robolectric
D. All of the above
ANSWER: D

Which class is used in Android to display large sets of data in a scrollable list?
A. ListView
B. RecyclerView
C. GridView
D. ScrollView
ANSWER: B

Which adapter is typically used with a RecyclerView in Android?


A. ArrayAdapter
B. RecyclerView.Adapter
C. SimpleAdapter
D. BaseAdapter
ANSWER: B

What is the purpose of the ViewHolder in RecyclerView?


A. To hold a reference to the layout's root view
B. To bind data to the view
C. To optimize view recycling
D. To create an adapter for the RecyclerView
ANSWER: C

In RecyclerView, which method is used to bind data to the ViewHolder?


A. onBindViewHolder()
B. onCreateViewHolder()
C. onItemClick()
D. onViewAttached()
ANSWER: A

Which layout manager is typically used to display items in a vertical list in


RecyclerView?
A. GridLayoutManager
B. LinearLayoutManager
C. StaggeredGridLayoutManager
D. FlexLayoutManager
ANSWER: B

Which of the following is true about RecyclerView?


A. It is a replacement for ListView
B. It does not support horizontal scrolling
C. It uses a static set of views
D. It automatically handles all data binding
ANSWER: A

What is the purpose of a LayoutManager in RecyclerView?


A. To define the size of each item
B. To create item views
C. To define how the items are arranged on the screen
D. To bind data to the view
ANSWER: C

Which method in RecyclerView.Adapter creates new ViewHolder objects?


A. onBindViewHolder()
B. onCreateViewHolder()
C. getItemCount()
D. onViewRecycled()
ANSWER: B

Which Android layout is best suited for positioning views in a grid format?
A. LinearLayout
B. RelativeLayout
C. ConstraintLayout
D. GridLayout
ANSWER: D

Which XML attribute is used to set the width of a view to match its parent
container in Android?
A. match_parent
B. fill_parent
C. wrap_content
D. parent_width
ANSWER: A

What is the role of the ConstraintLayout in Android?


A. To position elements based on weight
B. To arrange views using predefined constraints
C. To create static layouts
D. To create flexible grids
ANSWER: B

In Android, which element is used to display text on the screen?


A. Button
B. EditText
C. TextView
D. ImageView
ANSWER: C

Which of the following layout types helps to create a flexible user interface in
Android?
A. LinearLayout
B. RelativeLayout
C. ConstraintLayout
D. FrameLayout
ANSWER: C

Which XML attribute is used to give padding to a view in Android?


A. android:margin
B. android:padding
C. android:spacing
D. android:offset
ANSWER: B

In Android, what is the purpose of the ScrollView widget?


A. To display images
B. To contain multiple views in a scrollable format
C. To display a single line of text
D. To arrange views in a grid
ANSWER: B

Which testing framework is used for unit testing Android apps?


A. JUnit
B. Mockito
C. Espresso
D. Robolectric
ANSWER: A

Which tool is used to perform automated UI testing in Android?


A. JUnit
B. Espresso
C. Retrofit
D. OkHttp
ANSWER: B

Which command is used to build and install an APK on an Android device in Android
Studio?
A. Run
B. Build APK
C. Install APK
D. Run App
ANSWER: A

What file format is used to store the compiled Android application?


A. .app
B. .apk
C. .exe
D. .ipa
ANSWER: B

What is Android's Logcat tool used for?


A. To debug network issues
B. To view system logs and debug information
C. To generate performance reports
D. To package the app
ANSWER: B

In Android, which of the following is used to test the performance of an app?


A. Android Emulator
B. Android Studio Profiler
C. Logcat
D. Firebase
ANSWER: B
Which of the following is used to store key-value pairs in Android?
A. SharedPreferences
B. SQLite
C. ContentProvider
D. File Storage
ANSWER: A

What is the main use of SQLite in Android development?


A. To store data in a key-value pair format
B. To handle complex data queries in the app
C. To interact with web services
D. To display data in a list
ANSWER: B

Which Android component is used for working with local databases?


A. ContentProvider
B. SQLiteOpenHelper
C. Service
D. AsyncTask
ANSWER: B

What is the purpose of Room in Android?


A. To handle background tasks
B. To store encrypted data
C. To provide an abstraction layer for SQLite database
D. To send network requests
ANSWER: C

You might also like