Set-1 of FAQ on Mobile Application Development
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
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.
Q3: Discuss the role of Android Manifest file in Android application Development.
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.
ViewGroup
and are responsible for arranging their child views. TableLayout
and allows you to specify the number of rows and columns. Relatively less used in modern Android development.LinearLayout
in XML:In this example:
- The
LinearLayout
is set to a vertical orientation, so theTextView
andButton
will be arranged in a column. layout_width
andlayout_height
control the size of the views.match_parent
means the view will expand to fill its parent, whilewrap_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 theTextView
andButton
.
Q5: Create an application in Android to demonstrate various stages that an Activity goes through its lifecycle.
activity_main.xml:
Explanation:
-
Layout (activity_main.xml): A simple
LinearLayout
with aTextView
inside it. TheTextView
will be used to display the lifecycle events. -
Activity (MainActivity.java):
- The
MainActivity
class extendsAppCompatActivity
. - The
logAndAppend()
method logs the lifecycle event to Logcat (which you can view in Android Studio) and appends it to thelifecycleTextView
. - Each of the lifecycle methods (
onCreate()
,onStart()
,onResume()
,onPause()
,onStop()
,onDestroy()
,onRestart()
) is overridden. Inside each method, thelogAndAppend()
method is called to record the event.
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
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:
-
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.
-
Create a Virtual Device:
- In the AVD Manager window, click the "+ Create Virtual Device..." button.
-
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."
-
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.
-
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."
-
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.
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.
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()
, andonDestroy()
. 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.
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.