MOBILE PROGRAMMING EXAM
ANSWERS
QUESTION ONE (COMPULSORY)
1. 1. Primary programming language used for Android app development:
Java is the primary language used for Android development. It’s preferred because it is
officially supported by Android, has a large community, extensive libraries, and robust tools
like Android Studio.
2. 2. Functions of mobile application components:
- onCreate() method: Called when an activity is first created. It initializes the activity, sets
up the UI, and restores previous state if available.
- Activity: Acts as a single screen with a user interface in Android. It manages user
interaction and UI lifecycle.
3. 3. Meaning of Intent:
An Intent is a messaging object used to request an action from another app component. It
can start activities, services, or broadcast messages.
4. 4. Two reasons why Android is preferred:
- Open-source and free: Developers can access and modify the Android OS.
- Wider market reach: Android powers a large percentage of global mobile devices.
5. 5. Three types of native mobile applications:
- Productivity Apps: E.g., Calendars, Note-taking apps
- Gaming Apps: Native games utilizing device performance
- Social Media Apps: E.g., Facebook, Instagram
6. 6. Three layout classes:
- LinearLayout: Arranges children in a single row or column.
- RelativeLayout: Positions children relative to each other or the parent.
- ConstraintLayout: Allows complex positioning with constraints between components.
7. 7. Meaning of namespace + Sample XML code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
8. 8. Java code snippet to handle button clicks:
Button myButton = findViewById(R.id.my_button);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Button clicked!",
Toast.LENGTH_SHORT).show();
}
});
9. 9. XML code for emulator output:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome to Android App!"
android:textSize="18sp" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me" />
</LinearLayout>