0% found this document useful (0 votes)
16 views20 pages

MBL App Development

Uploaded by

MusHu BaLti
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)
16 views20 pages

MBL App Development

Uploaded by

MusHu BaLti
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/ 20

02.

2 Activity Lifecycle and State

1. Activity Lifecycle

Describes states of an activity from creation to destruction.

2. Activity states and app visibility

● Created (not visible yet)


● Started (visible)
● Resume (visible)
● Paused (partially invisible)
● Stopped (hidden)
● Destroyed (gone from memory)

3. Activity lifecycle callbacks

Callbacks and when they are called:

onCreate(Bundle savedInstanceState)—static initialization

onStart()—when Activity (screen) is becoming visible

onRestart()—called if Activity was stopped (calls onStart())

onResume()—start to interact with user

onPause()—about to resume PREVIOUS Activity


onStop()—no longer visible, but still exists and all state info preserved

onDestroy()—final call before Android system destroys Activity

4. Activity states and callbacks graph

5. Implementing and overriding callbacks

onCreate() –> Created

onStart() –> Started


onRestart() –> Started

onResume() –> Resumed/Running

onPause() –> Paused


onStop() –> Stopped

onDestroy() –> Destroyed

6. When does config change?

Configuration changes invalidate the current layout or other resources in your activity when the
user:
● Rotates the device
● Chooses different system language, so locale changes
● Enters multi-window mode (from Android 7)

7. What happens on config change?

On configuration change, Android:

1. Shuts down Activity by calling:

● onPause()
● onStop()
● onDestroy()

2. Starts Activity over again by calling:

● onCreate()
● onStart()
● onResume()

8. What the system saves?

● System saves only:


○ State of views with unique ID (android:id) such as text entered into EditText
○ Intent that started activity and data in its extras
● You are responsible for saving other activity and user progress data

9. Restoring instance state

Two ways to retrieve the saved Bundle

● in onCreate(Bundle mySavedState)
Preferred, to ensure that your user interface, including any saved state, is back up and
running as quickly as possible
● Implement callback (called after onStart())
onRestoreInstanceState(Bundle mySavedState)

2.3 Implicit Intents

1. What is an Intent?

An Intent is:

● Description of an operation to be performed


● Messaging object used to request an action from another app component via
the Android system.

2. What can an Intent do?

An Intent can be used to:

○ start an Activity
○ start a Service
○ deliver a Broadcast

Services and Broadcasts are covered in other lessons

3. Explicit vs. implicit Intent

Explicit Intent — Starts an Activity of a specific class


Implicit Intent — Asks system to find an Activity class with a registered handler

that can handle this request.

4. App Chooser

App Chooser to allow the user to select the handler.

5. Apps that handle common actions

Common actions are usually handled by installed apps (both system apps and other
apps), such as:

● Alarm Clock, Calendar, Camera, Contacts


● Email, File Storage, Maps, Music/Video
● Notes, Phone, Search, Settings
● Text Messaging and Web Browsing

3.1 The Android Studio debugger

1. Bugs

● Incorrect or unexpected result, wrong values

2. Debugging

● Find and fix errors


● Correct unexpected and undesirable behavior

3. Android Studio debugging tools

Android Studio has tools that help you

● identify problems
● find where in the source code the problem is created
● so that you can fix it

4. Log Levels

● Verbose - All verbose log statements and comprehensive system


● Debug - All debug logs, variable values, debugging notes
● Info - Status info, such as database connection
● Warning - Unexpected behavior, non-fatal issues
● Error - Serious error conditions, exceptions, crashes only

3.2 App testing

1. Why should you test your app?

• Find and fix issues early


• Less costly
• Takes less effort
• Costs to fix bugs, increases with time

2. Types of testing

● Levels of Testing
○ Component, integration, protocol, system
● Types of Testing
○ Installation, compatibility, regression, acceptance
○ Performance, scalability, usability, security
● User interface and interaction tests
○ Automated UI testing tools
○ Instrumented testing (covered in another chapter)
3. Tests in your project

Android Studio creates three source sets for your project

● main—code and resources


● (test)—local unit tests
● (androidTest)—instrumented tests

4. Unit tests

3.3 The Android Support Library

1. What are the Android support libraries?

o More than 25 libraries in the Android SDK that provide features not built into the
Android framework

Support library features

Support libraries provide:

o Backward-compatible versions of components


o Additional layout and UI elements, such as RecyclerView
o Different form factors, such as TV, wearables
o Material design and other new UI components for older Android versions
o and more….

Backward compatibility
Always use the support library version of a component if one is available

o No need to create different app versions for different versions of Android


o System picks the best version of the component

Libraries

v4 Support Libraries

o Largest set of APIs


o App components, UI features
o Data handling
o Network connectivity
o Programming utilities
o compat—compatibility wrappers
o core-utils—utility classes (eg., AsyncTaskLoader)
o core-ui—variety of UI components
o media-compat—back ports of media framework
o fragment—UI component

v7 Support Libraries

o Backwards compatibility
o TV-specific components
o UI components and layouts
o Google Cast support
o Color palette
o Preferences
o appcompat—compatibility wrappers
o cardview— new UI component (material design)
o gridlayout—rectangular cell (matrix) Layout
o mediarouter—route A/V streams
o palette—extracting color from an image
o recyclerview—efficient scrolling view
o preference—modifying UI settings

v7 appcompat library

● ActionBar and sharing actions


● You should always include this library and make AppCompatActivity the parent of your
activities

4.1 Buttons and clickable images

Touch Gestures

Touch gestures include:

● long touch
● double-tap
● fling
● drag
● scroll
● pinch

4.2 Input Controls

1. Accepting user input

○ Freeform text and numbers: EditText (using keyboard)


○ Providing choices: CheckBox, RadioButton, Spinner
○ Switching on/off: Toggle, Switch
○ Choosing value in range of values: SeekBar

Examples of input controls


1. EditText
2. SeekBar
3. CheckBox
4. RadioButton
5. Switch
6. Spinner

2. How input controls work?

1. Use EditText for entering text using keyboard


2. Use SeekBar for sliding left or right to a setting
3. Combine CheckBox elements for choosing more than one option
4. Combine RadioButton elements into RadioGroup — user makes only one choice
5. Use Switch for tapping on or off
6. Use Spinner for choosing a single item from a list

3. Clickable versus focusable

o Clickable—View can respond to being clicked or tapped


o Focusable—View can gain focus to accept input

Input controls such as keyboards send input to the view that has focus

4. Which View gets focus next?

○ Topmost view under the touch


○ After user submits input, focus moves to nearest neighbor—priority is left to right, top to
bottom
○ Focus can change when user interacts with a directional control
5. Common input types

4.3 Menus and pickers

1. Types of Menus

1. App bar with options menu


2. Context menu
3. Contextual action bar
4. Popup menu
2. Dialogs and pickers

3. What is the App Bar?

An app bar is a UI component that provides navigation, branding, and action elements at the top
of an application screen.

4. What is the options menu?


The options menu is a list of actionable items or settings that appears when users interact with a
designated menu icon, typically represented by three vertical dots.

5. What are contextual menus?

● Allows users to perform action on selected View


● Can be deployed on any View
● Most often used for items in RecyclerView, GridView, or other View collection

6. Types of contextual menus

● Floating context menu—long-press on a View


○ User can modify View or use it in some fashion
○ User performs action on one View at a time
● Contextual action mode—temporary action bar in place of or underneath app bar
○ Action items affect the selected View element(s)
○ User can perform action on multiple View elements at once

7. What is Action Mode?

Action Mode is a temporary, contextual user interface in Android that allows users to perform
specific actions on selected items, such as copy, delete, or share, typically displayed as a toolbar
at the top of the screen.

8. What is a contextual action bar?


A contextual action bar (CAB) is a temporary toolbar in Android that appears at the top of the
screen to provide context-specific actions when users select or interact with items, often used for
tasks like editing, sharing, or deleting content.

9. Introduction to fragments

● A Fragment is like a mini-Activity within an Activity


○ Manages its own own lifecycle
○ Receives its own input events
● Can be added or removed while parent Activity is running
● Multiple fragments can be combined in a single Activity
● Can be reused in more than one Activity

4.4 User navigation

1. Two forms of navigation

Back (temporal) navigation

● Provided by the device's Back button


● Controlled by the Android system back stack

Ancestral (Up) navigation

● Up button provided in app bar


● Controlled by defining parent Activity for child Activity in the AndroidManifest.xml

2. Hierarchical navigation patterns

● Parent screen—Screen that enables navigation down to child screens, such as home
screen and main Activity
● Collection sibling—Screen enabling navigation to a collection of child screens, such as a
list of headlines
● Section sibling—Screen with content, such as a story

3. Types of hierarchical navigation

● Descendant navigation
○ Down from a parent screen to one of its children
○ From a list of headlines—to a story summary—to a story
● Ancestral navigation
○ Up from a child or sibling screen to its parent
○ From a story summary back to the headlines
● Lateral navigation
○ From one sibling to another sibling
○ Swiping between tabbed views

4. Navigation drawer Activity layout

1. DrawerLayout is root view


2. CoordinatorLayout contains
app bar layout with a Toolbar
3. App content screen layout
4. NavigationView with layouts for header and selectable items

5. Steps to implement navigation drawer

1. Populate navigation drawer menu with item titles and icons


2. Set up navigation drawer and item listeners in the Activity code
3. Handle the navigation menu item selections
6. Benefits of using tabs and swipes

● A single, initially-selected tab—users have access to content without further navigation


● Navigate between related screens without visiting parent

4.5 RecyclerView

1. What is a RecyclerView?

● RecyclerView is scrollable container for large data sets


● Efficient
○ Uses and reuses limited number of View elements
○ Updates changing data fast
2. How components fit together overview

3. What is a layout manager?

A layout manager is a component in GUI frameworks (like Android or Java Swing) responsible
for arranging UI elements (views or components) within a container, defining their position, size,
and alignment dynamically based on the available space and layout rules.

4. What is an adapter?

An adapter in programming (commonly in Android) acts as a bridge between a data source and
a UI component, such as a ListView or RecyclerView, to display data dynamically in a
structured format.
5. What is a ViewHolder?

A ViewHolder is a design pattern in Android that holds references to views inside a


RecyclerView item to improve performance by avoiding unnecessary calls to findViewById
during scrolling.

You might also like