















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This entry-level exam covers Android fundamentals such as activity lifecycle, UI components, layout design, intents, data persistence options, networking basics, threading, and app packaging. It includes hands-on coding scenarios, debugging questions, and architecture considerations (MVC/MVVM). Ideal for beginners establishing a foundation in mobile development.
Typology: Exams
1 / 87
This page cannot be seen from the preview
Don't miss anything!
















































































Question 1. Which Kotlin keyword is used to declare an immutable reference? A) var B) val C) const D) final Answer: B Explanation: val creates a read‑only reference; its value cannot be reassigned after initialization. Question 2. In Kotlin, what does the safe‑call operator ?. do? A) Forces a null pointer exception B) Calls a method only if the receiver is non‑null, otherwise returns null C) Converts a nullable type to a non‑nullable type D) Performs a type cast Answer: B Explanation: The safe‑call operator executes the call only when the left‑hand operand isn’t null, returning null otherwise. Question 3. Which of the following is the correct way to define a default argument in a Kotlin function? A) fun foo(a: Int = 0) B) fun foo(a: Int?) C) fun foo(var a: Int) D) fun foo(a: Int: 0) Answer: A Explanation: Kotlin allows default values using the = syntax in the parameter list.
Question 4. What is the output type of a Kotlin when expression without an else branch when all branches return Int? A) Unit B) Any? C) Int D) Nothing Answer: C Explanation: When every branch returns the same type, the when expression’s type is that common type—in this case Int. Question 5. Which statement about Kotlin data classes is FALSE? A) They automatically generate equals() and hashCode() B) They cannot be open for inheritance C) They must have at least one primary constructor parameter D) They can contain mutable (var) properties only Answer: D Explanation: data classes may have val (immutable) or var (mutable) properties; they are not restricted to mutable only. Question 6. In Kotlin, how do you declare an extension function isEven() for Int? A) fun Int.isEven(): Boolean = this % 2 == 0 B) extension Int.isEven(): Boolean = ... C) Int.isEven() = this % 2 == 0 D) fun isEven(Int): Boolean Answer: A
Explanation: listOf returns a read‑only List. Question 10. In Kotlin, what is the purpose of the object declaration? A) To define a class that can be instantiated multiple times B) To create a singleton instance C) To declare an abstract class D) To define a data class without properties Answer: B Explanation: object creates a class and its single instance (singleton) automatically. Question 11. Which Android component is primarily responsible for handling long‑running background tasks without a UI? A) Activity B) Service C) BroadcastReceiver D) ContentProvider Answer: B Explanation: Services run in the background and can continue even when the UI is not visible. Question 12. What is the correct order of callbacks when an Activity is first launched? A) onCreate → onStart → onResume B) onResume → onStart → onCreate C) onStart → onCreate → onResume D) onCreate → onResume → onStart Answer: A
Explanation: The Activity lifecycle starts with onCreate, then onStart, and finally onResume. Question 13. Which method is used to save transient UI state before an Activity may be destroyed? A) onPause() B) onSaveInstanceState() C) onStop() D) onDestroy() Answer: B Explanation: onSaveInstanceState() receives a Bundle where you store UI state to be restored later. Question 14. How do you declare an explicit Intent to start DetailActivity from MainActivity? A) Intent(this, DetailActivity::class.java) B) Intent("com.example.DETAIL") C) Intent.ACTION_VIEW D) Intent.setClass(this, DetailActivity) Answer: A Explanation: The constructor (Context, Class<*>) creates an explicit Intent targeting a specific component. Question 15. Which XML attribute defines the layout width of a view to match its parent’s width? A) android:layout_height="match_parent" B) android:layout_width="wrap_content" C) android:layout_width="match_parent"
A) settings.gradle B) build.gradle (Project) C) build.gradle (Module: app) D) gradle.properties Answer: C Explanation: The module‑level build.gradle file declares implementation or api dependencies. Question 19. Which Android Studio window displays runtime logs and stack traces? A) Project pane B) Logcat C) Build Analyzer D) Terminal Answer: B Explanation: Logcat shows system and application log messages, useful for debugging. Question 20. Which command line tool is used to generate a signed APK for release? A) adb B) gradlew assembleRelease C) android D) sdkmanager Answer: B Explanation: Running ./gradlew assembleRelease builds a release‑signed APK using the signing config. Question 21. What does the android:configChanges attribute in the manifest control?
A) Which configuration changes trigger a full Activity restart B) Which permissions the app requires C) The default orientation of the Activity D) The minimum SDK version Answer: A Explanation: Specifying values like orientation|screenSize tells the system not to restart the Activity for those changes. Question 22. Which of the following is a correct way to retrieve a string resource in Kotlin code? A) resources.getString(R.string.app_name) B) getString(R.string.app_name) inside an Activity C) String(R.string.app_name) D) R.string.app_name.toString() Answer: B Explanation: Inside an Activity (or Context), getString() directly accesses the string resource. Question 23. Which method of SharedPreferences.Editor must be called to persist changes synchronously? A) apply() B) commit() C) save() D) flush() Answer: B Explanation: commit() writes changes to storage immediately and returns a boolean indicating success.
Explanation: Coroutines with Dispatchers.IO provide simple, cancellable background execution. Question 27. Which permission must be declared to allow an app to write to external storage on Android 9 (API 28) and lower? A) android.permission.READ_EXTERNAL_STORAGE B) android.permission.WRITE_EXTERNAL_STORAGE C) android.permission.MANAGE_EXTERNAL_STORAGE D) No permission is needed Answer: B Explanation: WRITE_EXTERNAL_STORAGE grants write access to external files on API ≤ 28; later versions require scoped storage. Question 28. Which lifecycle-aware component automatically updates the UI when data changes? A) Service B) LiveData C) BroadcastReceiver D) ContentProvider Answer: B Explanation: LiveData observes data and notifies active observers (e.g., UI) on changes. Question 29. In a RecyclerView.Adapter, which method creates new ViewHolder objects? A) onBindViewHolder B) getItemCount C) onCreateViewHolder
D) getItemViewType Answer: C Explanation: onCreateViewHolder inflates the item layout and returns a new ViewHolder. Question 30. Which XML attribute adds a margin of 16dp to the start side of a view, respecting RTL layouts? A) android:layout_marginLeft="16dp" B) android:layout_marginStart="16dp" C) android:marginStart="16dp" D) android:layout_marginHorizontal="16dp" Answer: B Explanation: layout_marginStart applies margin to the logical start side, adapting to RTL. Question 31. Which Android Jetpack component simplifies navigation between fragments and handles back‑stack management? A) ViewModel B) Navigation Component C) WorkManager D) DataBinding Answer: B Explanation: The Navigation Component provides a NavHost, NavController, and safe‑args for fragment navigation. Question 32. Which method in a Service is called when a client binds to it? A) onStartCommand B) onCreate
A) <uses-permission> B) <permission> C) <application> D) <intent-filter> Answer: B Explanation: <permission> defines a new permission name and protection level. Question 36. Which annotation is used to indicate that a method should be run on the UI thread in Android test code? A) @UiThreadTest B) @RunOnUiThread C) @MainThread D) @Test Answer: A Explanation: @UiThreadTest forces the test method to execute on the main (UI) thread. Question 37. What is the default launch mode of an Activity if none is specified? A) singleTop B) singleTask C) standard D) singleInstance Answer: C Explanation: standard creates a new instance each time the Activity is launched. Question 38. Which method of Toast displays a short‑duration message?
A) Toast.showLong() B) Toast.makeText(..., Toast.LENGTH_SHORT).show() C) Toast.displayShort() D) Toast.create(...).short() Answer: B Explanation: Toast.LENGTH_SHORT specifies a brief display time. Question 39. Which of the following best describes a FragmentTransaction? A) A background service that updates UI B) An API for adding, removing, or replacing fragments atomically C) A method to start a new Activity D) A way to bind data to a ListView Answer: B Explanation: FragmentTransaction batches fragment operations and commits them as a single atomic action. Question 40. In Android, which resource qualifier would you use for layouts designed for landscape orientation? A) layout-land B) layout-port C) layout-large D) layout-hdpi Answer: A Explanation: The -land qualifier selects resources when the device is in landscape mode. Question 41. Which method of AlertDialog.Builder sets a listener for the positive button?
Question 44. Which Gradle plugin is required to use Kotlin Android extensions? A) kotlin-android B) kotlin-kapt C) android-extensions D) kotlin-parcelize Answer: A Explanation: kotlin-android enables Kotlin support for Android modules. Question 45. Which Android API level introduced scoped storage, changing how apps access external files? A) API 21 B) API 23 C) API 29 D) API 30 Answer: C Explanation: Android 10 (API 29) introduced scoped storage, restricting direct file path access. Question 46. Which annotation tells Room to generate a primary key that auto‑increments? A) @PrimaryKey(autoGenerate = true) B) @ColumnInfo(primary = true) C) @AutoIncrement D) @Key Answer: A Explanation: Setting autoGenerate = true on @PrimaryKey lets Room assign incremental IDs.
Question 47. Which Android class is used to parse JSON strings into Kotlin/Java objects when using the Gson library? A) JsonParser B) Gson C) JSONObject D) JsonReader Answer: B Explanation: Gson provides fromJson() and toJson() methods for serialization. Question 48. Which method of View is called when the user touches the screen and you want to detect the gesture? A) onClick() B) onTouchEvent() C) onLongClick() D) onDrag() Answer: B Explanation: onTouchEvent receives MotionEvent objects for low‑level touch handling. Question 49. Which Android Studio feature can automatically generate getters and setters for Kotlin data class properties? A) Refactor → Extract → Method B) Code → Generate → Getter/Setter C) Right‑click → Generate → Kotlin Data Class D) No generation needed; properties are public by default Answer: D
D) Thread Answer: C Explanation: WorkManager schedules deferrable, guaranteed background tasks with constraints. Question 53. Which XML attribute is used to define a click handler method for a Button in layout XML? A) android:onClick="methodName" B) android:clickListener="methodName" C) android:onPress="methodName" D) android:handler="methodName" Answer: A Explanation: android:onClick links the button to a public method in the Activity. Question 54. Which of the following is NOT a valid ViewGroup layout parameter? A) layout_weight B) layout_gravity C) layout_alignParentStart D) layout_marginTop Answer: C Explanation: layout_alignParentStart belongs to RelativeLayout LayoutParams; not a generic ViewGroup param. Question 55. Which method of SharedPreferences retrieves a boolean value with a default of false? A) getBoolean("key", false)
B) readBoolean("key") C) fetchBool("key", false) D) boolean("key", false) Answer: A Explanation: getBoolean(key, defaultValue) returns the stored boolean or the default. Question 56. Which annotation is used to mark a method in a Kotlin interface as a suspend function for coroutines? A) @Suspendable B) suspend keyword (no annotation) C) @Async D) @Coroutine Answer: B Explanation: The suspend modifier declares a coroutine‑compatible function; no annotation is required. Question 57. Which Android class provides a way to observe lifecycle changes of an Activity or Fragment? A) LifecycleObserver B) Observer C) LiveData D) ViewModel Answer: A Explanation: Implementing LifecycleObserver and annotating methods with @OnLifecycleEvent lets you react to lifecycle events.