MCQs / Computer Science / Lab: Multiple Activities and Navigation

Lab: Multiple Activities and Navigation MCQs — Computer Science

14 multiple-choice questions on Lab: Multiple Activities and Navigation from Computer Science, each with the correct answer and, where available, a teacher's explanation. Read through them to revise the chapter, then practise the same questions one by one to test yourself.

1. When you add an activity using New → Activity in Android Studio, it automatically:

  1. Deletes MainActivity
  2. Creates a fragment
  3. Creates the class, its layout and the manifest entry
  4. Publishes the app

Answer: C) Creates the class, its layout and the manifest entry

Explanation: The wizard creates all three pieces.

Discuss this question

2. Which code creates an explicit intent for SecondActivity in Kotlin?

  1. startActivity(SecondActivity)
  2. Intent(this, SecondActivity::class.java)
  3. Intent("SecondActivity")
  4. Intent(Intent.ACTIONVIEW)

Answer: B) Intent(this, SecondActivity::class.java)

Explanation: The constructor takes a context and the target class.

Discuss this question

3. Extras are stored inside the intent as a:

  1. Bundle of key–value pairs
  2. SQLite table
  3. JSON file
  4. SharedPreferences file

Answer: A) Bundle of key–value pairs

Explanation: Intent extras are kept in a Bundle.

Discuss this question

4. The modern replacement for startActivityForResult() is:

  1. registerForActivityResult() with an ActivityResultLauncher
  2. onActivityResult() only
  3. setResult() alone
  4. startService()

Answer: A) registerForActivityResult() with an ActivityResultLauncher

Explanation: The Activity Result API replaces the deprecated startActivityForResult.

Discuss this question

5. Which method closes the current activity and returns to the previous one?

  1. finish()
  2. exit()
  3. close()
  4. stop()

Answer: A) finish()

Explanation: finish() destroys the activity and pops it from the back stack.

Discuss this question

6. android:exported="false" on SecondActivity means:

  1. Other apps cannot start this activity directly
  2. The activity is exported to iOS
  3. The activity cannot be opened at all
  4. The activity is hidden from the launcher only

Answer: A) Other apps cannot start this activity directly

Explanation: exported=false restricts launching to components of the same app.

Discuss this question

7. When the user returns to MainActivity from SecondActivity, MainActivity calls:

  1. onCreate() only
  2. onPause()
  3. onDestroy()
  4. onRestart(), onStart(), onResume()

Answer: D) onRestart(), onStart(), onResume()

Explanation: A stopped activity restarts when it becomes visible again.

Discuss this question

8. An intent that names the exact class to start is called:

  1. Explicit intent
  2. Implicit intent
  3. Sticky intent
  4. Pending intent

Answer: A) Explicit intent

Explanation: Explicit intents specify the target component by class.

Discuss this question

9. Which method sends a result back to the calling activity?

  1. putExtra(RESULT)
  2. returnData()
  3. setResult(RESULTOK, intent)
  4. sendBroadcast()

Answer: C) setResult(RESULTOK, intent)

Explanation: setResult with a result code and data intent, followed by finish().

Discuss this question

10. A new activity that is not declared in the manifest causes:

  1. Nothing; it works normally
  2. The app to open the browser
  3. A compile warning only
  4. ActivityNotFoundException at run time

Answer: D) ActivityNotFoundException at run time

Explanation: Every activity must be registered in AndroidManifest.xml.

Discuss this question

11. The manifest attribute that enables the Up button to return to MainActivity is:

  1. android:theme
  2. android:taskAffinity
  3. android:parentActivityName
  4. android:launchMode

Answer: C) android:parentActivityName

Explanation: parentActivityName defines the logical parent for Up navigation.

Discuss this question

12. Data is attached to an intent using:

  1. addData()
  2. putExtra()
  3. setText()
  4. sendData()

Answer: B) putExtra()

Explanation: putExtra(key, value) adds extras to the intent.

Discuss this question

13. When SecondActivity opens on top of MainActivity, MainActivity normally goes through:

  1. onPause() then onStop()
  2. onRestart() only
  3. onDestroy()
  4. onCreate() again

Answer: A) onPause() then onStop()

Explanation: The first activity becomes hidden, so it is paused and stopped but stays on the back stack.

Discuss this question

14. In SecondActivity, the passed name is read with:

  1. savedInstanceState.getName()
  2. intent.putExtra("NAME")
  3. getString("NAME")
  4. intent.getStringExtra("NAME")

Answer: D) intent.getStringExtra("NAME")

Explanation: getStringExtra(key) reads a string extra from the starting intent.

Discuss this question

Practise Lab: Multiple Activities and Navigation MCQs

More Computer Science chapters