You are on page 1of 22

MOBILE

APPLICATION
DEVELOPMENT
By Rohit Singh
Department of Computer Engineering
National Institute of Technology, Kurukshetra
PERFORMANCE AND
MULTITHREADING
 Developers multithread mobile applications in order to improve their performance and
usability.
 By spinning off processor or resource-intensive tasks into their own threads, the rest of the
program can continue to operate while these processor intensive tasks finish working.
 This can include separating the thread for the graphical user interface from the threads that
fetch network data.
 The JVM automatically manages these multiple tasks, so Android developers do not have to
concern themselves with optimizing thread performance for a particular set of hardware.
PERFORMANCE AND
MULTITHREADING
 When application component starts and the application does not have any other components
running, the Android system starts:
 a new Linux process with a single thread of execution (called the "main" thread).
 to control any certain component belongs to which process, use manifest file.
 The manifest entry for each type of component element— <activity>, <service>,
<receiver>, and <provider>— supports an android:process attribute that can specify a
process in which that component should run.
 <application> element also supports an android:process attribute, to set a default value that applies to
all components.
 Main thread is very important because it is incharge of dispatching events to the appropriate user
interface widgets
PERFORMANCE AND
MULTITHREADING
 A thread is a unit of a process and multiple such threads combine to form a process.
 When a process is broken, the equivalent number of threads are available.
 The main thread is also sometimes called the UI thread.
 All components that run in the same process are instantiated in the UI thread.
 For instance, when the user touches a button on the screen, app's UI thread dispatches the
touch event to the widget, which in turn sets its pressed state and posts an invalidate request to
the event queue. The UI thread dequeues the request and notifies the widget that it should
redraw itself.
 There are simply two rules:
1. Do not block the UI thread, it will present "application not responding" (ANR) dialog.
2. Do not access the Android UI toolkit from outside the UI thread.
PERFORMANCE AND
MULTITHREADING
 To prevent blocking, create "background" or "worker" threads.
 One can update the UI from UI thread or "main" thread only.
 To access the UI thread from other threads use following method:
 Activity.runOnUiThread(Runnable)
 View.post(Runnable)
 View.postDelayed(Runnable, long)
PERFORMANCE AND
MULTITHREADING
 Threads and app activity lifecycles:
 The app lifecycle can affect how threading works in your application.
 Decide, if a thread should, or should not, persist after an activity is destroyed.
 Threads continue to execute, uninterrupted, regardless of the creation or destruction of activities, although
gets terminated together with the application process once there are no more active application components.
 It’s important to set threads priority using setThreadPriority()
• If set too high, Thread may interrupt the UI thread.
• If set too low, will make async tasks (such as image loading) slower.
 By default, system assigns each thread its own priority value, using the Process class.
• THREAD_PRIORITY_DEFAULT represents the default value for a thread.
• THREAD_PRIORITY_BACKGROUND for threads that are executing less-urgent work.
• THREAD_PRIORITY_LESS_FAVORABLE and THREAD_PRIORITY_MORE_FAVORABLE constants as incrementers
to set relative priorities.
(Learn more at https://developer.android.com/reference/android/os/Process)
PERFORMANCE AND
MULTITHREADING
 A HandlerThread is effectively a long-running thread that grabs work from a queue and
operates on it.
 For example, when app delegates the Camera.open() command, the associated
onPreviewFrame() callback lands on the handler thread, rather than the UI thread. So, while
doing long-running work, handler thread may be a better solution.
 ThreadPoolExecutor is a helper class to make this process easier. This class manages:
• the creation of a group of threads.
• sets their priorities.
• manages how work is distributed among those threads.
PERFORMANCE AND
MULTITHREADING
 A HandlerThread is effectively a long-running thread that grabs work from a queue and
operates on it.
 For example, when app delegates the Camera.open() command, the associated
onPreviewFrame() callback lands on the handler thread, rather than the UI thread. So, while
doing long-running work, handler thread may be a better solution.
 ThreadPoolExecutor is a helper class to make this process easier. This class manages:
• the creation of a group of threads.
• sets their priorities.
• manages how work is distributed among those threads.
PERFORMANCE AND
MULTITHREADING
 How many threads should you create?
• Code has the ability to create hundreds of threads, but it creates performance issues.
• App shares limited CPU resources with background services, audio engine, networking, and
more.
• CPUs really only have the ability to handle a small number of threads in parallel.
• Everything runs on priority and scheduling, so it’s important to only create as many threads
as your workload needs.
• Threads also takes memory, minimum of 64k of memory.
• If app can reuse an existing threadpool, than reuse to increase performance by reducing load
on memory and processing resources.
ANDROID GRAPHICS
 Graphics are images or visual representation of objects as well as shapes displayed on screen.

 android.graphics provides low level graphics tools such as canvases, color filters, points, and rectangles
that let you handle drawing to the screen directly.

Camera A camera instance can be used to compute 3D transformations and generate a matrix that can be applied, for instance, on a Canvas.

Canvas The Canvas class holds the "draw" calls.

Color The Color class provides methods for creating, converting and manipulating colors.

ColorFilter A color filter can be used with a Paint to modify the color of each pixel drawn with that paint.

ColorMatrix 4x5 matrix for transforming the color and alpha components of a Bitmap.

ColorSpace A ColorSpace is used to identify a specific organization of colors.

DrawFilter A DrawFilter subclass can be installed in a Canvas.


ImageDecoder A class for converting encoded images (like PNG, JPEG, WEBP, GIF, or HEIF) into Drawable or Bitmap objects.
Paint The Paint class holds the style and color information about how to draw geometries, text and bitmaps.
ANDROID GRAPHICS
 android.graphics.text provide classes for manipulation with text.

LineBreaker Provides automatic line breaking for a single paragraph.

LineBreaker.Builder Helper class for creating a LineBreaker.

LineBreaker.ParagraphC Line breaking constraints for single paragraph.


onstraints
LineBreaker.Result Holds the result of the line breaking algorithm.

MeasuredText Result of text shaping of the single paragraph string.

MeasuredText.Builder Helper class for creating a MeasuredText.

PositionedGlyphs Text shaping result object for single style text.


TextRunShaper Provides conversion from a text into glyph array.
ANDROID GRAPHICS
 android.graphics.fonts provide classes for manipulation with font style.

Font A font class can be used for creating FontFamily.

Font.Builder A builder class for creating new Font.

FontFamily A font family class can be used for creating Typeface.

FontFamily.Builder A builder class for creating new FontFamily.

FontStyle A font style object.

FontVariationAxis Class that holds information about single font variation axis.

SystemFonts Provides the system font configurations.


ANDROID GRAPHICS
 android.graphics.drawable provides classes to manage a variety of visual elements that are
intended for display only, such as bitmaps and gradients. These elements are often used by
widgets as background images or simply as indicators (for example, a volume level indicator).

AnimatedImageDrawable Drawable for drawing animated images (like GIF).

AnimationDrawable An object used to create frame-by-frame animations, defined by a series of Drawable objects, which can be used as a
View object's background.
BitmapDrawable A Drawable that wraps a bitmap and can be tiled, stretched, or aligned.

Drawable A Drawable is a general abstraction for "something that can be drawn." Most often you will deal with Drawable as the
type of resource retrieved for drawing things to the screen; the Drawable class provides a generic API for dealing with an
underlying visual resource that may take a variety of forms.
Icon An umbrella container for several serializable graphics representations, including Bitmaps, compressed bitmap images
(e.g. JPG or PNG), and drawable resources (including vectors).
PaintDrawable Drawable that draws its bounds in the given paint, with optional rounded corners.

PictureDrawable Drawable subclass that wraps a Picture, allowing the picture to be used wherever a Drawable is supported.
ANDROID GRAPHICS
 android.graphics.drawable.shapes contains classes for drawing geometric shapes.

ArcShape Creates an arc shape.

OvalShape Defines an oval shape.

PathShape Creates geometric paths, utilizing the Path class.

RectShape Defines a rectangle shape.

RoundRectShape Creates a rounded-corner rectangle.

Shape Defines a generic graphical "shape."Any Shape can be drawn to a Canvas with its own draw() method,
but more graphical control is available if you instead pass it to a ShapeDrawable.
ANDROID GRAPHICS
 android.graphics.pdf contains classes for manipulation of PDF content.

PdfDocument This class enables generating a PDF document from native Android content.

PdfDocument.Page This class represents a PDF document page.

PdfDocument.PageInfo This class represents meta-data that describes a PDF Page.

PdfDocument.PageInfo.Builder Builder for creating a PageInfo.

PdfRenderer This class enables rendering a PDF document.

PdfRenderer.Page This class represents a PDF document page for rendering.


MOBILE AGENT
 An agent is a computer system that is situated in some environment, and that is capable of
autonomous action in this environment in order to meet its design objectives.
 Two basic properties of Software Agents:
 Autonomicity: ability to act without direct human intervention.
 Situatedness: Agents tend to be used where the environment is challenging (dynamic, unpredictable
and unreliable).
MOBILE AGENT
 Properties of Agent:
 Reactive: senses changes in the environment and acts accordingly to those changes.
 Proactive: persistently pursues goals.
 Flexible: has multiple ways of achieving goals.
 Robust: recovers from failure.
 Communicative: able to communicate with other agents.
 Mobile: can travel from one host to another.
 Learning: adapts in accordance with previous experience.
 Believable: appears believable to the end-user.
MOBILE AGENT
 WHAT IS A MOBILE AGENT?
 Program that can migrate from system to system within a network environment.
 Performs some processing at each host.
 Agent decides when and where to move next.
 How does it move?
• Save state
• Transport saved state to next system
• Resume execution of saved state
 Consists of software with data, which can move from one computing system to another autonomously.
 Functions for a device or system on the present host.
 Described as an autonomous software which runs on a host with some data.
 Dynamically moving software to another host (which has other required data) as and when required.
P2P ARCHITECTURE
 Peer-to-peer architecture (P2P architecture) is a commonly used computer networking
architecture in which each workstation, or node, has the same capabilities and responsibilities.
 It is often compared and contrasted to the classic client/server architecture, in which some
computers are dedicated to serving others.
 P2P may also be used to refer to a single software program designed so that each instance of
the program may act as both client and server, with the same responsibilities and status.
 Each system or device can send a request to and get a response from the other.
 Each device can have access to databases or database servers.
CHARACTERISTICS OF MOBILE
AGENT
1. Mobility of code and data from one computing system (host) to another.
2. Ability to learn in order to adapt code and data to the host computing system.
3. Ability to clone, extend, or dispose itself after its role finishes.
4. Compatibility to the hosts.
5. Ability to continuously and autonomously process requests and send responses and alerts.
ADVANTAGES OF MOBILE AGENT
1. Asynchronous running of codes on diversified heterogeneous hosts.
2. Reduced computational and data requirements on the devices with limited resources.
3. Tolerance to connection failures.
4. Only the agent source needs to be modified in order to redefine the functions expected from
the agent.
 Note: There is no need of a centralized or an application- specific server.

5. An agent can send the requests to a computing system as well as generate responses for
requests from the system.
6. An agent thus has certain similarities to peer-to-peer architecture.
7. The connection protocol and the connecting network between host and source are immaterial
THANK YOU

You might also like