Skip to main content

← Back to Past Papers

VNSGU BCA Sem 3: Mobile App Dev (305-2) Practical Solutions - April 2025 Set A

Paper Information

AttributeValue
SubjectMobile Application Development - I
Subject Code305-2
SetA
Semester3
Month/YearApril 2025
Max Marks25
PaperView Paper | Download PDF

Questions & Solutions

Q1: Fullscreen & Screen Orientation Toggle

Max Marks: 20

Create a Mobile Application in Android to hide title bar and open in Full Screen Size and change the orientation of the screen on button click.


1. Concept Explanation

Hiding the Title Bar and Action Bar

In Android, the title bar (Action Bar) can be hidden in two ways:

  1. XML Theme Config: Setting the theme in themes.xml to a NoActionBar variant (e.g. Theme.MaterialComponents.DayNight.NoActionBar).
  2. Programmatic Call: Using supportActionBar?.hide() inside the Activity's onCreate() method.

Running in Fullscreen Mode

To display an Activity in true fullscreen (hiding the status bar, navigation bar, etc.):

  • Modern APIs (API 30+): Use WindowInsetsController to hide system bars.
  • Legacy APIs: Use window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN).

Toggling Screen Orientation Programmatically

You can change the screen orientation of an activity on-the-fly by setting the requestedOrientation property:

  • ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
  • ActivityInfo.SCREEN_ORIENTATION_PORTRAIT

2. Algorithm & Step-by-Step Logic

  1. Design User Interface (activity_main.xml): Add a single Button in the center of a ConstraintLayout to act as the orientation toggler.
  2. Hide Title Bar programmatically:
    • In MainActivity.kt, call supportActionBar?.hide().
  3. Apply Fullscreen Flags:
    • Retrieve the window reference and apply layout flags to hide status/navigation bars.
  4. Implement Orientation Toggle Logic:
    • Bind a click listener to the button.
    • Check the current screen orientation via resources.configuration.orientation.
    • If it is Portrait (Configuration.ORIENTATION_PORTRAIT), set requestedOrientation to Landscape.
    • If it is Landscape, set requestedOrientation to Portrait.

3. Implementation Code & Output

View Solution & Output

Layout File: res/layout/activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#1E1E1E"
tools:context=".MainActivity">

<!-- Central Orientation Toggle Button -->
<Button
android:id="@+id/btnToggleOrientation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="Toggle Screen Orientation"
android:textSize="16sp"
android:backgroundTint="#FFBC3B"
android:textColor="#1A1A37"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Activity File: src/main/java/com/example/fullscreenapp/MainActivity.kt

// 📱 VNSGU BCA Sem 3 - Mobile Application Development (Practical 305-2)
// 🚀 Action: Configure Fullscreen, hide title bar, and toggle orientation dynamically.

package com.example.fullscreenapp

import android.content.pm.ActivityInfo
import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import android.view.WindowInsets
import android.view.WindowInsetsController
import android.view.WindowManager
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

// 1. Programmatic Title Bar Hiding
supportActionBar?.hide()

// 2. Programmatic Fullscreen Activation
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// Modern API 30+ implementation
window.insetsController?.let { controller ->
controller.hide(WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars())
controller.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
} else {
// Legacy implementation
@Suppress("DEPRECATION")
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
}

setContentView(R.layout.activity_main)

// 3. Orientation Toggling Logic on Button Click
val toggleButton: Button = findViewById(R.id.btnToggleOrientation)

toggleButton.setOnClickListener {
val currentOrientation = resources.configuration.orientation

if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) {
// Change to Landscape
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
Toast.makeText(this, "Switched to Landscape Mode", Toast.LENGTH_SHORT).show()
} else {
// Change to Portrait
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
Toast.makeText(this, "Switched to Portrait Mode", Toast.LENGTH_SHORT).show()
}
}
}
}

Manifest File: AndroidManifest.xml (Excerpt)

Ensure you add android:configChanges to your activity node. This tells the system that your activity will handle orientation changes itself, preventing the activity from restarting and reloading its state when the screen rotates:

<activity
android:name=".MainActivity"
android:exported="true"
android:configChanges="orientation|screenSize|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

💡 Common Examination Mistakes & Tips

Key Pitfalls to Avoid
  1. Call order issues: Always call supportActionBar?.hide() or layout parameters before calling setContentView(R.layout.activity_main). Otherwise, the layout is drawn before settings are applied, which can lead to visual glitches.
  2. No Configuration Handling: By default, Android restarts the current Activity when screen orientation changes. Always add android:configChanges="orientation|screenSize" to your activity inside AndroidManifest.xml to avoid data loss.
  3. Modern vs Legacy APIs: Show knowledge of WindowInsetsController for SDK 30+ instead of relying solely on deprecated WindowManager flag settings.

📍 Visit Us

🏫 VD Computer Tuition Surat

VD Computer Tuition
📍 Address
2/66 Faram Street, Rustompura
Surat395002, Gujarat, India
📞 Phone / WhatsApp
+91 84604 41384
🌐 Website

Computer Classes & Tuition — Areas We Serve in Surat

AdajanAlthanAmroliAthwaAthwalinesBhagalBhatarBhestanCanal RoadChowkCitylightDumasGaurav PathGhod Dod RoadHaziraJahangirpuraKamrejKapodraKatargamLimbayatMagdallaMajura GateMota VarachhaNanpuraNew CitylightOlpadPalPandesaraParle PointPiplodPunaRanderRing RoadRustampuraSachinSalabatpuraSarthanaSosyo CircleUdhnaVarachhaVed RoadVesuVIP Road
📞 Call Sir💬 WhatsApp Sir