Introduction to Android and Kotlin
Introduction to Android and Kotlin
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
Which Android component is responsible for responding to user inputs like button
clicks?
A. Intent
B. Activity
C. Service
D. View
ANSWER: D
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 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
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
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 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
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
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
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 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
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 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 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
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 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 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
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 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