Android Basic Terms
Android Basic Terms
User interface elements usually fall into one of the following four
categories:
• Input Controls
• Navigation Components
• Informational Components
• Containers
INPUT CONTROLS
Element Description
Checkboxes Checkboxes allow the user to select one or more options
from a set. It is usually best to present checkboxes in a
vertical list. More than one column is acceptable as well if
the list is long enough that it might require scrolling or if
comparison of terms might be necessary.
Radio Radio buttons are used to allow users to select one item
at a time.
buttons
Dropdown Dropdown lists allow users to select one item at a time,
similarly to radio buttons, but are more compact allowing
lists you to save space. Consider adding text to the field, such
as ‘Select one’ to help the user recognize the necessary
action.
List boxes List boxes, like checkboxes, allow users to select a multiple
items at a time,but are more compact and can support a
longer list of options if needed.
Buttons A button indicates an action upon touch and is typically
labeled using text, an icon, or both.
Element Description
Dropdown lists Dropdown lists allow users to select one item at
a time, similarly to radio buttons, but are more
compact allowing you to save space. Consider
adding text to the field, such as ‘Select one’ to
help the user recognize the necessary action.
List boxes List boxes, like checkboxes, allow users to select
a multiple items at a time, but are more
compact and can support a longer list of options
if needed.
Buttons A button indicates an action upon touch and is
typically labeled using text, an icon, or both.
Dropdown The dropdown button consists of a button that
when clicked displays a drop-down list of
Button mutually exclusive items.
Navigational Components
Element Description
Search Field A search box allows users to enter a
keyword or phrase (query) and submit
it to search the index with the
intention of getting back the most
relevant results. Typically search fields
are single-line text boxes and are often
accompanied by a search button.
Breadcrumb Breadcrumbs allow users to identify
their current location within the
system by providing a clickable trail of
proceeding pages to navigate by.
Pagination Pagination divides content up between
pages, and allows users to skip
between pages or go in order through
the content.
Element Description
Sliders A slider, also known as a track bar, allows users to set or
adjust a value. When the user changes the value, it does
not change the format of the interface or other info on
the screen.
Icons An icon is a simplified image serving as an intuitive
symbol that is used to help users to navigate the system.
Typically, icons are hyperlinked.
Information Components
Element Description
Notifications A notification is an update message that announces
something new for the user to see. Notifications are
typically used to indicate items such as, the successful
completion of a task, or an error or warning message.
Progress Bars A progress bar indicates where a user is as they
advance through a series of steps in a process.
Typically, progress bars are not clickable.
Tool Tips A tooltip allows a user to see hints when they hover
over an item indicating the name or purpose of the
item.
Containers
Element Description
Accordion An accordion is a vertically stacked list of items that utilizes show/ hide functionality.
When a label is clicked, it expands the section showing the content within. There can have
one or more items showing at a time and may have default states that reveal one or more
sections without the user clicking
FRAGMENTS
• Android Fragment is the part of activity, it is also known as sub-activity. There can be more than
one fragment in an activity. Fragments represent multiple screen inside one activity.
• Android fragment lifecycle is affected by activity lifecycle because fragments are included in
activity.
• A fragment has its own layout and its own behaviour with its own life cycle callbacks.
• You can add or remove fragments in an activity while the activity is running.
• You can combine multiple fragments in a single activity to build a multi-pane UI.
• A fragment can be used in multiple activities.
• Fragment life cycle is closely related to the life cycle of its host activity which means when the
activity is paused, all the fragments available in the activity will also be stopped.
• A fragment can implement a behaviour that has no user interface component.
METHODS TO OVERRIDE IN YOUR FRAGMENT CLASS
• onAttach() it is called only once when it is attached with activity.
• onCreate() It is used to initialize the fragment.
• onCreateView() creates and returns view hierarchy.
• onActivityCreated() It is invoked after the completion of onCreate() method.
• onStart() - makes the fragment visible..
• onResume() - makes the fragment interactive..
• onPause() - Is called when fragment is no longer interactive.
• 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.
• onDetach() - It is called immediately prior to the fragment no longer being associated with its activity
HOW TO USE FRAGMENTS?
• This involves number of simple steps to create Fragments.
• First of all decide how many fragments you want to use in an activity. For
example let's we want to use two fragments to handle landscape and portrait
modes of the device.
• Next based on number of fragments, create classes which will extend
the Fragmentclass. The Fragment class has above mentioned callback
functions. You can override any of the functions based on your requirements.
• Corresponding to each fragment, you will need to create layout files in XML
file. These files will have layout for the defined fragments.
• Finally modify activity file to define the actual logic of replacing fragments
based on your requirement.
INTENT
• An Intent is a simple message object that is used to communicate
between android components such as activities, content providers,
broadcast receivers and services.
• Intents are also used to transfer data between activities.
• Use of Intent
• For Launching an Activity
• To start a New Service
• For Broadcasting Messages
• To Display a list of contacts in ListView
Types of Intent in Android
Intent is of two types:
• Implicit Intent
• Explicit Intent
• Implicit Intent
• The implicit intent is the intent where instead of defining the exact components,
you define the action that you want to perform for different activities.
• An Implicit intent specifies an action that can invoke any app on the device to be
able to perform an action. Using an Implicit Intent is useful when your app cannot
perform the action but other apps probably can and you’d like the user to pick
which app to use.
• Explicit Intent
• An explicit intent is an Intent where you explicitly define the
component that needs to be called by the Android System. An explicit
intent is one that you can use to launch a specific app component, such
as a particular activity or service in your app.
The Different Methods Used in Intent
• Action_Main
• Action_Pick
• Action_Chooser
• Action_Dial
• Action_Call
• Action_Send
• Action_SendTo
Content Provider
• A content provider manages access to a central repository of data.
• A provider is part of an Android application, which often provides its own UI for
working with the data.
• Content providers are primarily intended to be used by other applications
• Which access the provider using a provider client object. Together, providers and
provider clients offer a consistent, standard interface to data that also handles
inter-process communication and secure data access.
A content provider coordinates access to the data storage layer in your application
for a number of different APIs and components, these include:
• The Drag and Drop process starts when user making gestures recognized as a signal to start dragging data and
application tells the system that the drag is starting.
• In android, the Drag and Drop process contains a 4 steps or states, those are
Started
Continuing
Dropped
Ended
DATA AND FILE STORAGE OVERVIEW
• Android provides several options for you to save your app data.
• The solution you choose depends on your specific needs, such as how much space your data
requires, what kind of data you need to store, and whether the data should be private to your
app or accessible to other apps and the user.
• Internal file storage: Store app-private files on the device file system.
• External file storage: Store files on the shared external file system. This is usually for shared
user files, such as photos.
• Shared preferences: Store private primitive data in key-value pairs.
• Databases: Store structured data in a private database.
INTERNAL FILE STORAGE
• By default, files saved to the internal storage are private to your app.
• This makes internal storage a good place for internal app data that the user doesn't need
to directly access.
• The system provides a private directory on the file system for each app where you can
organize any files your app needs.
• When the user uninstalls app, the files saved on the internal storage are removed.
• Because of this behavior, you should not use internal storage to save anything the user
expects to persist independently of your app.
• For example, if your app allows users to capture photos, the user would expect that
they can access those photos even after they uninstall your app.
• So you should instead use the mediastore API to save those types of files to the
appropriate media collection6
External storage
• Every Android device supports a shared "external storage" space that you can use to save files.
This space is called external because it's not guaranteed to be accessible.
• It is a storage space that users can mount to a computer as an external storage device, and it
might even be physically removable (such as an SD card).
• Files saved to the external storage are world-readable and can be modified by the user when
they enable USB mass storage to transfer files on a computer.
• So before you attempt to access a file in external storage in your app, you should check for the
availability of the external storage directories as well as the files you are trying to access.
• Most often, you should use external storage for user data that should be accessible to other
apps and saved even if the user uninstalls your app, such as captured photos or downloaded
files.
• The system provides standard public directories for these kinds of files, so the user has one
location for all their photos, ringtones, music, and such.
SHARED PREFERENCES
• If you don't need to store a lot of data and it doesn't require structure, you should use
SharedPrefrences.
• The SharedPrefrences APIs allow you to read and write persistent key-value pairs of primitive
data types: booleans, floats, ints, longs, and strings.
• The key-value pairs are written to XML files that persist across user sessions, even if your app is
killed. You can manually specify a name for the file or use per-activity files to save your data.
• The API name "shared preferences" is a bit misleading because the API is not strictly for saving
"user preferences," such as what ringtone a user has chosen.
• You can use SharedPrefrences to save any kind of simple data, such as the user's high score.
• if you do want to save user preferences for your app, then you should read how to create a
settings UI, which uses the AndroidX Prefrence Libraryto build a settings screen and automatically
persist the user's settings.
Databases