Search This Blog

Friday, 14 February 2025

Frequently Asked Questions (Set 1) on MAD

0 comments

 Set-1 of FAQ on Mobile Application Development



30 MCQs on Mobile Application Development (Test Your Knowledge on MAD)

Q1:  Discuss the 
Layered Architecture of Android OS.

Android is an open-source software stack that includes the following stack of software components for the benefits of its users:

  • an Operating System
  • middleware
  • a set of API libraries
  • key mobile applications
Figure: Android Application Stack


Android is made up of collection of software which consists of a Linux kernel and a collection of C/C++ libraries that are exposed through an application framework for the development and execution of android applications.  The Android software stack consists of the following:

i.   A Linux kernel, a low-level interfae that provides an abstaction between the hardware and the remainder of the stack.

ii.  Open source libraries for application development, including SQLite, webkit and Open GL

iii. A run-time system for executing and hosting Android applications, for e.g., Dalvik Virtual Machine (Dalvi VM), which is designed to be small and efficient for use on mobile devices.

iv. An application framework and a user interface framework for developing and hosting applications.

v.  A set of core pre-installed applications, which include:

a) An e-mail client

b) An SMS application

c) A Personal Information Management suite of software

d) A music player and picture gallery

e) A calculator

vi. A Software Development Kit (SDK) which is used to create applications

       Linux kernel is the core part of the Android OS, which takes care of handling low-level hardware interaction including drivers and memory management.  It takes care of the core services of the OS such as:

a)  Managing hardware drivers

b)  Process and memory management

c)  Security, network and power management

Running on top of the kernel, we have various C/C++ libraries that include the following:

  A media library for playback of audio and video files

  A surface manager to provide display management

  Graphics libraries that include SGL and OpenGL for 2D and 3D graphics

  SQLite for native database supports

  SSL and webkit for integrated web browser and Internet security

Android runtime system is part of the Android OS, with the help of which applications can access resources such as memory and processor during execution.  Android VM and Android runtime system sit on top of the Linux kernel.  A virtual machine such as Dalvik is used instead of traditional Java VM for running android applications.  Each android application runs in a separate process within the Android Virtual Machine (Dalvik instance). 

The application framework provides API in the form SDK that consists of classes and interfaces to create android applications.   It provides a generic abstraction for applications to access hardware such as IO devices.  Higher level programming language such as Java is used for developing applications that can run on Android.


Q2:  An Activity usually loses its current state.  What should be done in order to preserve the state of the Activity?

With the multitasking nature of mobile devices, it is likely that an Android application will regularly move into and out of the background.  Therefore, it is important that they "come to life" quickly and seamlessly.  This attribute of seamlessness can be achieved by storing the state of the activity when it is suspended and use the state information later when the application is resuming.

Every activity goes through a set of states during its life cycle.  The state of an Activity helps in determining the priority of its parent application.  In order to manage the state of all activities in an application a mechanism called - Activity Stack is provided in Android runtime system.

Figure: Activity Stack of Android


Activity Stack is a storage mechanism that determines the state of each Activity in an Application.  The position of an Activity   in the Activity State tells us its state.  When a new Activity starts, it becomes active and is moved to the top of the stack.  If the user navigates back using Back button, the next Activity down on the stack moves up and becomes active.

Q3: Discuss the role of Android Manifest file in Android application Development.

The Android Manifest file is a crucial part of every Android application.  It's an XML file that describes essential information about your app to the Android system, including permissions, hardware requirements, activities, services, and more.  Without a properly configured manifest, your app won't function correctly.

Think of it as the app's declaration of identity and capabilities.  The manifest declares the package name, which uniquely identifies your application.  This is essential for distinguishing your app from others in the Google Play Store and on the device.  It also specifies the app's version code and version name, which are used for updates and user identification.

The manifest describes all the components of your application.  They are also registered in the manifest.  The components of an application that are described in the manifest file are as follows:

  • Activities: These represent the screens or user interfaces of your app. Each activity needs to be declared in the manifest.
  • Services: These are background processes that perform tasks without a user interface. They are also registered in the manifest.
  • Broadcast Receivers: These components listen for system-wide broadcasts, like changes in network connectivity or battery status. They must be declared to receive these broadcasts.
  • Content Providers: These components manage shared data, like a database.

The manifest also has the specification of hardware and software that an application application requires.  
One of the most important roles of the manifest is to declare the permissions your app requires. If an android application needs access to the camera, internet, location, or other sensitive resources, the developer must explicitly request permissions for these resources in the manifest.    

Q4: What are all the Layouts available to Android developers for developing an application?  Write the code snippet that makes use of any one of the Layout Views.

Android offers a variety of layout options to help developers create flexible and responsive user interfaces. These layouts are subclasses of ViewGroup and are responsible for arranging their child views.  

Here is the list of Layouts available in Android for developing an android application:

LinearLayout: Arranges views in a single row or column. It's simple and efficient for basic layouts. You can control the orientation (vertical or horizontal), gravity, and weight of child views.

RelativeLayout: Positions views relative to each other or the parent layout. It's useful for creating more complex layouts where the position of one view depends on another. You can define relationships like "below," "to the right of," or "aligned with.

FrameLayout: A simple layout that stacks views on top of each other. Only the top-most view is visible. It's often used for displaying a single view, like an image, or for overlaying views, like a progress bar on top of an image.

TableLayout: Arranges views in rows and columns, similar to an HTML table. It's useful for creating grid-like layouts. Relatively less used in modern Android development.

GridLayout: Arranges views in a grid of rows and columns. It's more flexible than TableLayout and allows you to specify the number of rows and columns. Relatively less used in modern Android development.

Here's an example of a simple LinearLayout in XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"  >  

<TextView android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />

<Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Click Me" />
</LinearLayout>

In this example:

  • The LinearLayout is set to a vertical orientation, so the TextView and Button will be arranged in a column.
  • layout_width and layout_height control the size of the views. match_parent means the view will expand to fill its parent, while wrap_content means it will be just big enough to contain its content.
  • The android:id attribute gives each view a unique identifier, which can be used to reference the view in your code.
  • android:text sets the text displayed in the TextView and Button.

Q5: Create an application in Android to demonstrate various stages that an Activity goes through its lifecycle.

MainActivity.java

package com.example.activitylifecycle;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "ActivityLifecycle";
    private TextView lifecycleTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        lifecycleTextView = findViewById(R.id.lifecycleTextView);
        logAndAppend("onCreate()");
    }

    @Override
    protected void onStart() {
        super.onStart();
        logAndAppend("onStart()");
    }

    @Override
    protected void onResume() {
        super.onResume();
        logAndAppend("onResume()");
    }

    @Override
    protected void onPause() {
        super.onPause();
        logAndAppend("onPause()");
    }

    @Override
    protected void onStop() {
        super.onStop();
        logAndAppend("onStop()");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        logAndAppend("onDestroy()");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        logAndAppend("onRestart()");
    }



    private void logAndAppend(String lifecycleEvent) {
        Log.d(TAG, lifecycleEvent); // Log to Logcat

        // Append to TextView (Make sure you have a TextView in your layout)
        if (lifecycleTextView != null) {  //Check for null to avoid crashes.
            lifecycleTextView.append(lifecycleEvent + "\n");
        }
    }
}

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<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/lifecycleTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:textColor="@android:color/black" />

</LinearLayout>

Explanation:

  1. Layout (activity_main.xml): A simple LinearLayout with a TextView inside it. The TextView will be used to display the lifecycle events.

  2. Activity (MainActivity.java):

    • The MainActivity class extends AppCompatActivity.
    • The logAndAppend() method logs the lifecycle event to Logcat (which you can view in Android Studio) and appends it to the lifecycleTextView.
    • Each of the lifecycle methods (onCreate(), onStart(), onResume(), onPause(), onStop(), onDestroy(), onRestart()) is overridden. Inside each method, the logAndAppend() method is called to record the event.

Q6: List out the features of Android SDK.

Android provides its API in the form of SDK.  Some of the noteworthy features provided in Android SDK are as follows:

1. Android supports different types of connectivity for GSM, CDMA, Wi-Fi, Bluetooth, etc. for telephonic conversation or data transfer.

2. Using wifi technology we can pair with other devices while playing games or using other applications.

3. It contains multiple APIs to support location-tracking services such as GPS.

4. We can manage all data storage-related activities by using the file manager.

5. It supports a wide range of media files like AVI, MKV, FLV, MPEG4, etc. to play or record a variety of audio/video.

6. It also supports different image formats like JPEG, PNG, GIF, BMP, MP3, etc.

7. It supports multimedia hardware control to perform playback or recording using a camera and microphone.

8. Android has an integrated open-source WebKit layout-based web browser to support User Interfaces like HTML5, and CSS3.

9. Android supports multi-tasking, i.e., we can run multiple applications at a time and can switch between them.

10.It provides support for virtual reality or 2D/3D Graphics.

 

By providing APIs in the form of SDK, android supports the development of applications in the following ways:

i.  Simplifies application development involving the underlying device hardware

ii. Supports location-based hardware, the camera, audio, network connection, wi-fi, bluetooth, sensors, NFC, the touch screens and power management

iii.Offers rich support for transferring data between devices such as Bluetooth, wi-fi direct and Android beam

iv. Enables its application developers to manage network connections, bluetooth connections, and NFC tag reading

v.  Allows application developer to use embedded map to create map-based applications that will leverage the mobility of Android devices


Q7: What is AVD?  How do you create AVD in an IDE like Android Studio?

AVD stands for Android Virtual Device. It's an emulator that simulates a real Android device on your computer, allowing you to test your Android applications without needing a physical device. 

AVDs are essential for Android development because they allow you to test your app on various Android versions, screen sizes, and hardware configurations. This helps ensure your app works correctly on a wide range of devices.Here's how you create an AVD in Android Studio:

  1. Open the AVD Manager:

    • From the Welcome Screen: If you haven't opened a project yet, you should see a "Configure" button. Click it and select "AVD Manager."
    • From an Open Project: Go to Tools -> AVD Manager.
  2. Create a Virtual Device:

    • In the AVD Manager window, click the "+ Create Virtual Device..." button.
  3. Select Hardware Profile:

    • You'll see a list of predefined hardware profiles for various devices (phones, tablets, Wear OS devices, Android TV). Choose a profile that represents the type of device you want to emulate. You can also create a custom hardware profile if needed.
    • Click "Next."
  4. Select System Image:

    • This step is crucial. You need to select the Android system image (the Android version) that you want to run on the virtual device. You'll see a list of available system images. It is recommended to select a system image that corresponds to your targetSdkVersion or compileSdkVersion.
    • Important: You might need to download system images if they aren't already present. Click the "Download" link next to the system image you want to use. This can take some time, as system image files are large. Look for the "Recommended" tab for images that are stable and widely used.
    • Click "Next" after selecting the system image.
  5. Configure the AVD:

    • Give your AVD a name (e.g., "Pixel 7 API 33").
    • You can configure additional settings here, such as:
      • Startup orientation: Portrait or landscape.
      • Graphics: Choose between Automatic, Hardware, or Software. Hardware is generally faster if your computer supports it.
      • Memory and Storage: Adjust RAM and internal storage. Be careful not to allocate too much memory, as it can slow down your system. The defaults are usually fine.
      • Show Advanced Settings: Here you can customize many other options like camera, network, sensors, etc. Usually, the defaults are fine.
    • Click "Finish."
  6. Run the AVD:

    • Your newly created AVD will appear in the AVD Manager list.
    • Click the green "Play" button next to the AVD to launch it. The first time you launch an AVD, it can take a while, but subsequent launches will be faster.

Q8: Explain the various types of Android applications.

Android applications are of four types:

1.      Foreground application

2.      Backgroud application

3.      Intermittent applicationsWidgets and

4.      Live wallpapers

 

Foreground Application

   Foreground applications are applications that are useful only when they are in the foreground.  They are suspended when they are not visible.

   Game applications are the applications are of this kind.

   Care must be given to manage the Activity lifecycle of foreground applications sothat the Activity switches seamlessly between the backgound and the background.

   The developer of such application has to save the state of the application when it leaves the foreground, and then present the same state when it returns to the front.

Background Applications

   Background applications run silently in the background with little user input.

   Examples of such applications include

   Call screening applications

   SMS auto-responders

   Alarm clocks

   Background applications are often listen for messages or actions caused by hardware, system or other applications

Intermittent Applications

   These applications can accept user input when it is in the foreground and at the same time respond to events when it is running at the background.

   Chat and e-mail applications are of Intermittent type of applications.

   Intermittent applications are built using components such as

   Visible Activities

   Invisible background services and

   Broadcast Receivers

   Intermittent appications must update the Activity UI and send notifications to keep the user updated when it is running in the background.

Widgets and Live Wallpaper

   These applications are available on home-screen and visible to the user.

   They provide interactive visual components that can add functionality to user’s home screen.

Widget only applications are commonly used to display dynamic information to the user such as battery levels, weather forecast, date and time etc.


Q9: Discuss in details the various components of an Android application.

An Android application is composed of several key components that work together to create the user experience and handle various tasks. Here's a detailed discussion of these components:

1. Activities:

  • Role: An Activity represents a single, focused screen with a user interface. Think of it as a screen in your app. Most apps consist of multiple activities, each responsible for a specific task or displaying a specific set of information.
  • Lifecycle: Activities have a lifecycle, a series of states they go through, including onCreate(), onStart(), onResume(), onPause(), onStop(), and onDestroy(). Developers need to manage these states to handle configuration changes (like screen rotation), save and restore data, and manage resources efficiently.
  • Interaction: Users interact with Activities through UI elements (buttons, text fields, etc.). Activities respond to these interactions and perform actions accordingly.
  • Example: In a social media app, there might be separate activities for viewing the news feed, composing a post, viewing a profile, or managing settings.

2. Services:

  • Role: Services are background processes that perform long-running operations without a user interface. They are used for tasks like downloading files, playing music, or syncing data in the background.
  • Types:
    • Foreground Services: Perform tasks that are noticeable to the user (e.g., playing music) and display a notification to keep the user aware.
    • Background Services: Perform tasks in the background without directly notifying the user (e.g., syncing data). Android has restrictions on background services to optimize battery life.
    • Bound Services: A service that can be bound to an activity, allowing the activity to interact with the service.
  • Example: A music player app might use a service to continue playing music even when the app is in the background or the screen is off.

3. Broadcast Receivers:

  • Role: Broadcast Receivers listen for system-wide broadcasts, which are messages sent by the system or other apps. They can respond to events like changes in network connectivity, battery status, or incoming SMS messages.
  • Registration: Broadcast Receivers need to be registered in the AndroidManifest.xml file or dynamically at runtime to listen for specific broadcasts.
  • Example: An app might use a Broadcast Receiver to detect when the device's network connectivity changes and adjust its behavior accordingly.

4. Content Providers:

  • Role: Content Providers manage shared data, like a database. They provide a standardized way for apps to access and modify data from other apps (if permissions allow).
  • Data Sharing: Content Providers are often used to share data between apps.
  • Example: The Contacts app uses a Content Provider to allow other apps to access the user's contact information.

5. Intents:

  • Role: Intents are messaging objects that are used to communicate between different components (Activities, Services, Broadcast Receivers) within an app or between different apps.
  • Types:
    • Explicit Intents: Specify the exact component to be started (e.g., a specific Activity in your app).
    • Implicit Intents: Declare the action you want to perform (e.g., "open a web page") and allow the system to determine which app can handle the intent.
  • Example: When you click a link in an email app, an implicit intent is used to open the link in a web browser app.

Q10: What are Fragments?  Explain the various stages of the lifecycle of a fragment.

Fragments are reusable components that represent portions of a user interface (UI) within an Activity. They were introduced primarily to handle the more complex UI designs needed for tablets and other large-screen devices, but they are now a standard part of Android development even for phones. 

Think of a Fragment as a mini-Activity that can be embedded within an Activity. An Activity can host one or more Fragments, allowing you to create dynamic and flexible layouts.  Here the key aspects of Fragments and their lifecycle:

  • Reusability: Fragments can be reused across different Activities or within the same Activity, promoting modularity and code reuse.
  • Dynamic UI: Fragments allow you to change parts of the Activity's UI at runtime. For example, you can replace one Fragment with another based on user interaction or device orientation.
  • Tablet Support: Fragments are particularly useful for creating adaptive UIs for tablets. You can display multiple Fragments side-by-side on a larger screen and arrange them differently on a smaller screen.
  • Simplified Activity Management: By breaking down the UI into smaller, manageable Fragments, you can simplify the code and structure of your Activities.


  • Figure: Various Stages of the Lifecycle of a Fragment

    Android fragments have their own life cycle very similar to an android activity.  Here is the list of methods which you can to override in your fragment class:

    • onAttach()The fragment instance is associated with an activity instance.The fragment and the activity is not fully initialized. Typically you get in this method a reference to the activity which uses the fragment for further initialization work.

    • onCreate() The system calls this method when creating the fragment. You should initialize essential components of the fragment that you want to retain when the fragment is paused or stopped, then resumed.

    • onCreateView() The system calls this callback when it's time for the fragment to draw its user interface for the first time. To draw a UI for your fragment, you must return a View component from this method that is the root of your fragment's layout. You can return null if the fragment does not provide a UI.

    • onActivityCreated()The onActivityCreated() is called after the onCreateView() method when the host activity is created. Activity and fragment instance have been created as well as the view hierarchy of the activity. At this point, view can be accessed with the findViewById() method. example. In this method you can instantiate objects which require a Context object

    • onStart()The onStart() method is called once the fragment gets visible.

    • onResume()Fragment becomes active.

    • onPause() The system calls this method as the first indication that the user is leaving the fragment. This is usually where you should commit any changes that should be persisted beyond the current user session.

    • onStop()Fragment going to be stopped by calling onStop()

    • onDestroyView()Fragment view will destroy after call this method

    • onDestroy()onDestroy() called to do final clean up of the fragment's state but Not guaranteed to be called by the Android platform.


    Leave a Reply