0% found this document useful (0 votes)
13 views44 pages

MAD Ch2 Part One

The document provides an overview of generic UI development for Android applications, emphasizing best practices such as understanding the Android platform architecture, writing clean code, and optimizing app performance. It details the activity lifecycle, explaining the various states an activity goes through and the corresponding callback methods. Additionally, it highlights the importance of app security and designing user-friendly interfaces.

Uploaded by

lulieeliyas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views44 pages

MAD Ch2 Part One

The document provides an overview of generic UI development for Android applications, emphasizing best practices such as understanding the Android platform architecture, writing clean code, and optimizing app performance. It details the activity lifecycle, explaining the various states an activity goes through and the corresponding callback methods. Additionally, it highlights the importance of app security and designing user-friendly interfaces.

Uploaded by

lulieeliyas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

Generic UI Development

Chapter 2
Contents

➔ Generic UI Development
➔ Building Layout
➔ Describe Intents
➔ Describe Services
➔ Explain characteristics of mobile applications
➔ Successful mobile application development
Generic UI Development
Generic UI Development
➔ Creating a generic user interface (UI) involves leveraging the
platform's rich set of components and adhering to best
practices that ensure a responsive and user-friendly
experience.
➔ Here’s an overview of the key aspects involved in generic
UI development for Android apps.
• Understand the Android Platform Architecture
• Follow the Android App Development Process
• Write Clean and Readable Code
• Use Third-Party Libraries and Frameworks
• Optimize App Performance
• Ensure App Security
• Design User-Friendly and Accessible Interfaces
Understand the Android Platform Architecture

➔ Android architecture
contains a different
number of components
to support any Android
device’s needs.
➔ Understanding
Android’s architecture
is essential for
building efficient
applications.
Understand the Android Platform Architecture
cont…

1. Applications is the top layer of android architecture.


➔ The pre-installed applications like home, contacts,
camera, gallery etc and third party applications
downloaded from the play store like chat applications,
games etc.will be installed on this layer only.

➔ It runs within the Android run


time with the help of the
classes and services provided
by the application framework.
cont…

2. Application Framework provides several important classes


which are used to create an Android application.
➔ It includes different types of services activity manager,
notification manager, view system, package manager etc.
cont…

3. Android Runtime environment is one of the most important


part of Android. It contains components like core libraries
and the Dalvik virtual machine(DVM).
➔ Dalvik Virtual Machine (DVM) is a register-based virtual
machine and specially designed and optimized for android
to ensure that a device can run multiple instances
efficiently.
➔ The core libraries enable us to
implement android applications
using the standard JAVA or
Kotlin programming languages.
cont…

4. The Platform Libraries includes various C/C++ core


libraries and Java based libraries.
➔ Media library provides support to play and record an
audio and video formats.
➔ Surface manager responsible for managing access to the
display subsystem.
cont…

➔ SGL and OpenGL both cross-language, cross-platform


application program interface (API) are used for 2D and 3D
computer graphics.
➔ SQLite provides database support and FreeType provides
font support.
➔ Webkit This open source web browser engine provides all
the functionality to display web content and to simplify
page loading.
➔ SSL (Secure Sockets Layer) is security technology to
establish an encrypted link between a web server and a web
browser.
cont…

5. Linux Kernel is heart of the android architecture. It


manages all the available drivers.
➔ The Linux Kernel will provide an abstraction layer between
the device hardware and the other components of android
architecture.
➔ It is responsible for management of memory, power, devices
etc. The features of Linux kernel are:
cont…

➔ Security: The Linux kernel handles the security between the


application and the system.
➔ Memory Management: It efficiently handles the memory
management thereby providing the freedom to develop our apps.
➔ Process Management: It manages the process well, allocates
resources to processes whenever they need them.
➔ Network Stack: It effectively handles the network
communication.
➔ Driver Model: It ensures that the application works properly
on the device and hardware manufacturers responsible for
building their drivers into the Linux build.
Follow the Android App Development Process
Follow the Android App Development Process

➔ Building an Android app ain’t just a


one-step process.
➔ Android app development process
typically involves series of stages
and
➔ following a structured development
process is a key to provide a
top-notch app that gets the job done
right, and meets your users’
expectations.
Write Clean and Readable Code
Write Clean and Readable Code

➔ To make sure your Android app is easy to


maintain, expand, and scale, it’s really
important that you write clean code
that’s easy to read.
➔ The more understandable and simple you
can make your code, the better off
you’ll be in the long run.
➔ Give your variables, functions, and
comments clear and descriptive names, so
that it’s easy to figure out what’s
going on along with that don’t forget to
review your code.
Use Third-Party Libraries and Frameworks
Use Third-Party Libraries and Frameworks

➔ Using third-party libraries and frameworks in developing


your Android app can save you a ton of time and effort.
➔ There are different tools out there to help make your
app-building journey smoother, with some of the most popular
options for Android development including
• Glide (perfect for image loading),
• Retrofit (great for networking),
• ButterKnife (ideal for view binding),
• Dagger (perfect for dependency injection), and
• Google Play Services (super useful for location, maps and
more).
Optimize App Performance
Optimize App Performance
You have to make sure that your app loads up swiftly,
responds promptly to user input, and performs seamlessly, no
matter the kind of network or device your users are using.
➔ Optimize your app performance by following these best
practices:
• Minimize app startup time: Use lazy loading,
preloading, and caching to reduce app startup time.
• Use background processing: Use background threads,
services, and jobs to perform long-running tasks and
improve app responsiveness.
Cont…
● Optimize memory usage: Use the memory
profiler to identify memory leaks and
optimize memory usage.
● Optimize network usage: Use HTTP
caching, network timeouts, and
compression to reduce network usage and
improve response time.
● Optimize battery usage: Use the Doze
mode and App Standby mode to reduce
battery consumption.
Ensure App Security
Ensure App Security
App security is essential to protect user data and prevent
unauthorized access and attacks. Your app needs to follow
the best practices and guidelines for app security, such as:
● Use encryption: Use encryption to protect sensitive data,
such as passwords, financial information, and personal
information.
● Use authentication: Use secure authentication mechanisms,
such as OAuth, Google sign-in, and biometric
authentication, to ensure that only authorized users can
access your app.
Cont…
● Use sandboxing: Use a sandboxed environment to isolate
your app from other apps and prevent data leakage or
malicious activities.
● Use secure network protocols: Use HTTPS, SSL/TLS, or
other secure network protocols to protect network
communications and prevent eavesdropping or
man-in-the-middle attacks.
● Test for vulnerabilities: Test your app for security
vulnerabilities, such as SQL injection, cross-site
scripting, and buffer overflow, using automated or manual
security testing tools.
Design User-Friendly and Accessible Interfaces
Design User-Friendly and Accessible Interfaces
Some best practices and guidelines for user interface design
include:
● Use familiar patterns: Use familiar design patterns and
conventions, such as action bars, navigation drawers, and
material design, to ensure that your app feels familiar
and intuitive to your users.
● Design for different screen sizes: Design your app
interface to adapt to different screen sizes and
resolutions, including tablets, phones, and wearables.
The Android platform provides tools, such as layout
managers, to help with this.
Cont…

● Use contrast and color intelligently: Use contrast and


color to highlight important elements and provide visual
cues for navigation and interaction.
● Ensure accessibility: Ensure that your app interface is
accessible to users with disabilities, such as vision
impairment or motor impairment, by following
accessibility guidelines and adding accessibility
features, such as text-to-speech or large text.
What is Activity?
Activity
➔ In Android, an activity represents a single screen with a
user interface that the user can interact with.
➔ It is a crucial component of an Android app, responsible for
displaying content, handling user input, and managing the
app's workflow.
➔ An Android app may contain one or more activities, and the
app starts by showing the main activity.
➔ Activities are similar to windows in desktop applications.
➔ Activities are a combination of XML files (for design) and
Java/Kotlin files (for coding and functionality).
➔ To use activities in your app , you must register them in
the app’s manifest.
Activity Lifecycle
➔ An activity goes through different states during its
lifetime, from creation to destruction.
➔ The activity lifecycle manages these states using callback
methods.
➔ Understanding the activity lifecycle is crucial for handling
state changes effectively and preventing abnormal app
behavior.
…cont’d…
onCreate()

➔ This is the first method that is called when the activity is


first created.
➔ Used to initialize UI components and variables calling
setContentView(int) to inflate the activity's UI,
➔ using findViewById(int) to programmatically interact with
widgets in the UI

Example: Set up UI, initialize databases,Initializing


variables or restore saved state.
onCreate()
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

// Bundle containing previous frozen state


setContentView(R.layout.activity_main);

// The content view pointing to the id of layout


Toast toast = Toast.makeText(getApplicationContext(), "onCreate Called",
Toast.LENGTH_LONG).show();
}

savedInstanceState - is bundle object which contain the previously saved data of


the Activity.
onStart()

➔ This method is called when the activity becomes visible to the


user.
➔ This is the point where the activity is ready to interact with
the user. UI is prepared but not yet interactive
➔ It is followed by onResume() if the activity is invoked from the
background.
➔ It is also invoked after onCreate() when the activity is first
started.
Cont…
Usage of onStart()
➔ Preparing UI components (e.g., updating UI based on the latest
data).
➔ Starting animations or UI updates.
➔ Registering listeners (e.g., location updates, sensors, or
broadcasts).
➔ Fetching data from a database or API to display updated
information.
protected void onStart()
{
// It will show a message on the screen
// then onStart is invoked
Toast toast = Toast.makeText(getApplicationContext(),
"onStart Called",
Toast.LENGTH_LONG).show();
}
onResume()

➔ This method is called when the activity is in the foreground and


has focus.
➔ At this point, the activity is fully interactive, and the user
can interact with the UI.
➔ It is invoked when the activity starts interacting with the
user.the activity is at the top of the activity stack, with a
user interacting with it. Always followed by onPause() when the
activity goes into the background or is closed by the user.
Cont..
Usage of onResume()
➔ Resume animations, videos, or audio that were paused in
onPause().
➔ Restart sensors or listeners (e.g., GPS, accelerometer,
microphone).
➔ Check for new data updates (e.g., refresh messages in a chat
app).
➔ Authenticate users if needed (e.g., revalidate a session).

protected void onResume() {


// It will show a message on the screen
// then onRestart is invoked
Toast toast = Toast.makeText(getApplicationContext(),
"onResume Called",
Toast.LENGTH_LONG).show();
}
onPause()
➔ This method is called when the activity loses focus but is still
visible to the user.
➔ This can happen when another activity is launched on top of the
current activity.
➔ It is invoked when an activity is going into the background but
has not yet been killed.

protected void onPause() {


// It will show a message on the screen
// then onPause is invoked
Toast toast = Toast.makeText(getApplicationContext(),
"onPause Called", Toast.LENGTH_LONG).show();
}
Cont…

Usage of onPause()
→ Pause running processes (e.g., media playback, animations,
sensor updates).
→ Save user progress (e.g., store form data, game state, or
draft messages).
→ Release resources (e.g., unregister listeners, stop
background threads).
→ Reduce power consumption (e.g., stop GPS tracking when not
needed).
onStop()

➔ This method is called when the activity is no longer visible


to the user.
➔ This can happen when the user navigates to another activity
or when the activity is destroyed
➔ It is followed by onRestart() when the activity is revoked
from the background,
➔ followed by onDestroy() when the activity is closed or
finished, and nothing when the activity remains on the
background only
Cont…

In onStop(), you should perform tasks such as:


➔ Saving any important data.
➔ Releasing resources that are not needed while the
activity is stopped.
➔ Stopping animations or ongoing processes (like network
calls or background services) to conserve resources.

protected void onStop() {


// It will show a message on the screen
// then onDestroy is invoked
Toast toast = Toast.makeText(getApplicationContext(), "onStop
Called", Toast.LENGTH_LONG).show();
}
onRestart()
➔ This method is called when the activity is stopped and then
started again.
➔ This can happen when the user navigates back to the activity.
➔ It is invoked after the activity has been stopped and prior to
its starting stage
➔ and thus is always followed by onStart() when any activity is
revived from background to on-screen.

protected void onRestart() {


// It will show a message on the screen
// then onRestart is invoked
Toast toast = Toast.makeText(getApplicationContext(), "onRestart
Called", Toast.LENGTH_LONG).show();
}
onDestroy()
➔ This is the final method that is called when the activity is
destroyed.
➔ This method is responsible for releasing any resources that were
allocated by the activity.
➔ The final call received before the activity is destroyed. This
can happen either because the activity is finishing (when
finish() is invoked) or because the system is temporarily
destroying this instance of the activity to save space.

protected void onDestroy() {


// It will show a message on the screen
// then onRestart is invoked
Toast toast = Toast.makeText(getApplicationContext(), "onDestroy
Called", Toast.LENGTH_LONG).show();
}

You might also like