Xamarin Certification Xamarin.Android Development 1 — Questions and Answers
Question 1: Which attribute marks a class as an Android Activity in Xamarin.Android?
- [Activity] (Correct answer)
- [Register]
- [Export]
- [Component]
Correct answer: [Activity]
The [Activity] attribute registers a C# class as an Android Activity and allows setting properties like Label and MainLauncher.
Question 2: In Xamarin.Android, which method is the first lifecycle callback when an Activity is created?
- OnCreate (Correct answer)
- OnStart
- OnResume
- OnInitialize
Correct answer: OnCreate
OnCreate is called when the Activity is first created and is where you initialize views and state.
Question 3: What method inflates an XML layout resource in Xamarin.Android?
- SetContentView (Correct answer)
- LayoutInflater.Inflate
- FindViewById
- LoadLayout
Correct answer: SetContentView
SetContentView inflates and sets the XML layout as the Activity's content view.
Question 4: Which class is used to start a new Activity in Xamarin.Android?
- Intent (Correct answer)
- Navigator
- ActivityManager
- Task
Correct answer: Intent
An Intent object specifies the target Activity and is passed to StartActivity to launch it.
Question 5: In Xamarin.Android, which attribute is required to declare permissions in the app manifest?
- [UsesPermission] (Correct answer)
- [Permission]
- [Requires]
- [Manifest]
Correct answer: [UsesPermission]
The [UsesPermission] assembly-level attribute adds a <uses-permission> entry to AndroidManifest.xml.
Question 6: What is the role of a Fragment in Xamarin.Android?
- Represents a reusable portion of UI within an Activity (Correct answer)
- Handles network requests
- Manages app-wide state
- Provides a database interface
Correct answer: Represents a reusable portion of UI within an Activity
Fragments are modular UI components that are hosted by an Activity and have their own lifecycle.
Which attribute marks a class as an Android Activity in Xamarin.Android?