Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Notes 3

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

User Interface Architecture

In an Android application, the user interface is built using View and ViewGroup objects. There are many types of
views and view groups, each of which is a descendant of the View class.

View objects are the basic units of user interface expression on the Android platform. The View class serves as the
base for subclasses called "widgets," which offer fully implemented UI objects, like text fields and buttons. The
ViewGroup class serves as the base for subclasses called "layouts," which offer different kinds of layout
architecture, like linear, tabular and relative.

A View object is a data structure whose properties store the layout parameters and content for a specific
rectangular area of the screen. A View object handles its own measurement, layout, drawing, focus change,
scrolling, and key/gesture interactions for the rectangular area of the screen in which it resides. As an object in the
user interface, a View is also a point of interaction for the user and the receiver of the interaction events.

View Hierarchy
On the Android platform, you define an Activity's UI using a hierarchy of View
and ViewGroup nodes, as shown in the diagram below. This
hierarchy tree can be as simple or complex as you need it to be,
and you can build it up using Android's set of predefined widgets
and layouts, or with custom Views that you create yourself.

Application Context

 The Context tells us about the surrounding information.


 It is very important to understand the environment which we want to understand.
 It allows us to access resources.
 It allows us to interact with other Android components by sending messages.
 It gives you information about your app environment.

1. It is the Context of the current/active state of the application.


Usually, the app got multiple screens like display/inquiry/add/delete screens(A
general requirement of a basic app). So when the user is searching for something,
the Context is an inquiry screen in this case.
2. It is used to get information about the activity and application.
The inquiry screen’s Context specifies that the user is in inquiry activity, and he/she
can submit queries related to the app
3. It is used to get access to resources, databases, shared preferences,
etc.
Via Rest services, API calls can be consumed in android apps. Rest Services
usually hold database data and provide the output in JSON format to the android
app. The Context for the respective screen helps to get hold of database data and
the shared data across screens
4. Both the Activity and Application classes extend the Context class.
In android, Context is the main important concept and the wrong usage of it leads
to memory leakage. Activity refers to an individual screen and Application refers to
the whole app and both extend the Context class.

Types of Context in Android


There are mainly two types of Context that are available in Android.
1. Application Context and
2. Activity Context

Widgets
A widget is a View object that serves as an interface for interaction with the user. Android provides a set of fully
implemented widgets, like buttons, checkboxes, and text-entry fields, so you can quickly build your UI. Some
widgets provided by Android are more complex, like a date picker, a clock, and zoom controls. But you're not
limited to the kinds of widgets provided by the Android platform. If you'd like to do something more customized and
create your own actionable elements, you can, by defining your own View object or by extending and combining
existing widgets.

Layout
The most common way to define your layout and express the view hierarchy is with an XML layout file. XML offers
a human-readable structure for the layout, much like HTML. Each element in XML is either a View or ViewGroup
object (or descendant thereof). View objects are leaves in the tree, ViewGroup objects are branches in the tree.

Intents in Android
In Android, it is quite usual for users to witness a jump from one application to
another as a part of the whole process, for example, searching for a location on the
browser and witnessing a direct jump into Google Maps or receiving payment links
in Messages Application (SMS) and on clicking jumping to PayPal or GPay (Google
Pay). This process of taking users from one application to another is achieved by
passing the Intent to the system. Intents, in general, are used for navigating
among various activities within the same application, but note, is not limited to one
single application, i.e., they can be utilized from moving from one application to
another as well.
Intents could be Implicit, for instance, calling intended actions, and explicit as well,
such as opening another activity after some operations like onClick or anything
else. Below are some applications of Intents:
1. Sending the User to Another App
2. Getting a Result from an Activity
3. Allowing Other Apps to Start Your Activity
Important Method of Intent and their Description

Methods Description

Context.startActivity() This is to launch a new activity or get an existing activity to be action.

This is to start a new service or deliver instructions for an existing


Context.startService()
service.

The activity lifecycle

To navigate transitions between stages of the activity lifecycle,


the Activity class provides a core set of six
callbacks: onCreate(), onStart(), o
nResume(), onPause(), onStop(),
and onDestroy(). The system
invokes each of these
callbacks as the activity
enters a new state.
Figure 1 presents a visual representation of
this paradigm.

You might also like