SlideShare a Scribd company logo
1 of 31
WELCOME to…
8th September 2022
This work is licensed under the Apache 2.0 License
Aneesh Gupta
(2nd Year student in CSE Branch)
WHO AM I ?
 My tech stack –
 Android
 Flutter
 JAVA, Kotlin, Dart, XML
 Real Projects Experience -> Working in start-ups to
accomplish real world problems.
 Hobbies ->
 Solving real problems
First Android App
Build App UI
App architecture &
Navigation
Layouts, Lists &
Material
This work is licensed under the Apache 2.0 License
● Activity & Lifecycle
● What is Architecture & it’s Principles?
● Layers in Architecture
● What is Navigation?
● How to achieve Navigation?
Today’s AGENDA…
This work is licensed under the Apache 2.0 License
 Faith-Based learning
 Abstraction level of learning
How to study DEVELOPMENT ?
This work is licensed under the Apache 2.0 License
ACTIVITY
 Activity is the entry point for interacting with the user.
 During it’s lifetime, it transitions through various states which is known as
ACTIVITY LIFECYCLE.
 Activity lifecycle extends from the creation of the activity to its destruction.
 If an activity doesn’t respond correctly to lifecycle state changes, app can
generate bugs, strange behavior and may consume too many Android
resources.
Activity Lifecycle
onCreate() -> called
when activity is first
created.
onStart() -> called
when activity is
visible to user.
onResume() -> called
when activity is
interactable with the
user
onDestroy() -> called
when activity is
destroyed
onStop() -> called
when activity is no
longer visible to the
user
onPause() -> called
when activity is
about to lose focus.
This work is licensed under the Apache 2.0 License
Hands-on on
Activity Lifecycle
(A small demo on how activity lifecycle callbacks work)
This work is licensed under the Apache 2.0 License
ARCHITECTURE
 Designing pattern and techniques to construct the app to have a right
structure to remain functional and safe under challenging conditions
 Advantages –
 Easier to Test
 Makes App Robust
 Easy to Collaborate
 Makes App Scalable
PRINCIPLES
()(Must be Followed)
This work is licensed under the Apache 2.0 License
SOC
()(Separation of Concern)
Every component must have it’s own functionality and must not
intervene with the logic of other components.
For eg. UI components must know only about UI composables and
should not know anything about the data to be presented in the UI.
UDF
()(Unidirectional Flow)
UI Components must ask the Data component for the data to be
displayed on the screen and similarly, should expose any event /
user interaction to the data component to update the data
accordingly.
This work is licensed under the Apache 2.0 License
● Activity’s lifecycle is tied to the Android Operating System.
● Change in configuration of the app results in creation of a new
instance for the activity.
● If Data of the app is maintained within the activity, it might get
lost and hence, we would loose the state of our app!!
● So, it’s important to separate all the app data and resources into
such files which are independent of the Android framework.
How to Apply ??
To achieve the same, we’ll now think of UI and Data as 2 separate layers
 Data Layer - a layer that displays the app data on the screen but is independent of
the data
 UI Layer - a layer that stores, retrieves, and exposes the app data.
This work is licensed under the Apache 2.0 License
Hands-on on
Activity Configuration Changes
(How data is lost if stored in activity during
configuration changes)
WHAT IS STATE?
 State in an app is any value that can change over time.
• For eg. In a TextField, state is the TEXT that is being entered by the user. As soon as the user types in a new
character, the state of the TextField (i.e. it’s text) is changed.
 Compose is declarative and as such the only way to update it is by calling the same composable with new
arguments. (i.e. a New State)
 Any time a state is updated a recomposition takes place.
 As a result, things like TextField don’t automatically update like they do in imperative XML based views. A
composable has to explicitly be told the new state in order for it to update accordingly.
This work is licensed under the Apache 2.0 License
UI is what user sees, BUT UI State is what the app says
they should see…
UI is a result of binding UI elements on the screen with
UI state…
This work is licensed under the Apache 2.0 License
NEED OF UDF
 If code in both layers hold refence of each
other and there’s no unidirectional flow, then
there’s no Separation of Concern.
 There must be flow of data in the following
manner ->
 UI exposes events to Data.
 Data changes and updates are observed
by UI.
Data Layer
UI Layer
Data Layer
UI Layer
Events Data
Hence, Unidirectional Flow is important, else would lead to
Data dependency on Android Framework
Layers of UI
 UI Layer has 2 components –
• UI Elements (Composables)
• State Holders (ViewModel)
 ViewModel holds and exposes state that the
UI elements consume.
 It stores the app related data that isn’t
destroyed when the activity is destroyed and
recreated by Android Framework
 Unlike the activity instance, ViewModel
objects are not destroyed on configuration
change
 This frees up the UI and make it focus solely
on to read and update the UI elements
accordingly.
This work is licensed under the Apache 2.0 License
This work is licensed under the Apache 2.0 License
How to implement ViewModel?
StateFlow
It’s a data holder observable flow that emits the current
and new state updates. (In our eg, the new UI State)
To update state and send it to the flow, assign a new
value to the value property of the Mutable State Flow
class.
It can be exposed from the new UI State, so that the
composables can listen for UI updates and make screen
state survive configuration changes.
Backing Property
A backing property lets you return something from a getter
other than the exact object.
To implement a backing property, you override the getter
method to return a read-only version of your data.
This backing property protects the app data inside the
ViewModel from unwanted and unsafe changes by external
classes, but it lets external callers safely access its value.
Before we proceed, we need to understand the following terms ->
This work is licensed under the Apache 2.0 License
Hands-on on ViewModel
(What do you need to know to implement a ViewModel)
This work is licensed under the Apache 2.0 License
Create UIState
Create GameUIState data class
consisting of the different state
components of the app which will
be exposed to UI by ViewModel to
make updates in UI
Get Current State
of the App
Use asStateFlow() on a
mutableStateFlow instance
(i.e. GameUIState instance here) to
implement Backing property on UI
State.
Get Random word
to be displayed
Implement a new function to get
unused random word.
Summarizing UnScramble App
Create ViewModel
Create a GameViewModel
extending ViewModel class
ViewModel in
Composable
Instantiate ViewModel in Parent
Composable.
Get State in
Composable from
ViewModel
Use collectAsState() to obtain
new UiState from ViewModel
Pass Lambda
Expressions for
events
ViewModel receives the events via
lambda expressions and update
UIState accordingly which is then
observed by the
mutableStateFlow instance in
Composable.
Handle Last
Round
As soon as the size of set
containing usedWords becomes
equal to 10, show a popup, to the
user, in which if Play Again is
selected, reset the game, else
finish the activity.
Let’s try change in
device configuration…
You’ll observe that when the device is rotated, though activity
gets destroyed and is being created again by the Android
Operating System, but the state of the app doesn’t change. This
is because ViewModel’s instance doesn’t get cleared off and
therefore the new Composables so formed get their data to be
displayed from the state stored with ViewModel.
This work is licensed under the Apache 2.0 License
ViewModel is a life-saver for change in
configurations…
This work is licensed under the Apache 2.0 License
NAVIGATION…
 Till Now, you saw Single Screen Apps in all our session. But now, let’s deep
dive into Multi-Screen Apps.
 Navigation Compose Component allows you to build multiscreen apps in
Compose using a declarative approach.
 You’ll also get to know how to send data from your app to another
using intents.
This work is licensed under the Apache 2.0 License
● NavController : Used to navigate b/w destinations
(screens of the app)
● NavGraph : Maps composable destinations
● NavHost : Composable Container for displaying
current destination
Parts of Navigation Component
This work is licensed under the Apache 2.0 License
( How to properly implement Navigation in
multi-screen app while we respect the
architecture principles such as SOC )
Hands-on on Navigation
This work is licensed under the Apache 2.0 License
Steps to achieve Navigation
2 3 5
4
1
Define
Routes
• Route -> A string
corresponding to a
specific destination.
• Route is a unique
identifier for a
destination.
• HOW TO DEFINE
ONE -> Using Enum
classes
Initialize
NavHost
• Displays a specific
screen on the basis
of route selected.
• Mandatory
arguments ->
NavController &
StartDestination
(first screen to be
shown by default)
Understanding
NavController
• NavHostController instance
helps to navigate to
different screens using
navigate() function.
• Obtained by calling
rememberNavController()
Handle
Routes
• Navhost takes
composable()
function as it’s
content.
• For each screen, a
separate
composable() is
required which
consists of route name
and the Composable
to be displayed.
Respect
Architecture
• We can’t pass
NavController as a
parameter to every
screen to handle
navigation. (Each
screen should not be
aware of any other
screen)
• Hence, we pass a
function type in each
composable to handle
the navigation.
This work is licensed under the Apache 2.0 License
 Sometimes, we have to send some data from our
app to another app (For eg. while making
payments, the app usually navigates us to some
other payment-making app).
 Since, this functionality is provided by the Android
Operating System, we don’t use NavController, but
something called an INTENT.
Navigating to Another App
This work is licensed under the Apache 2.0 License
Steps to achieve Navigation to
Another App
• Pass any additional data
to intent by using
putExtra() method.
• Intent takes 2 extras ->
EXTRA_SUBJECT &
EXTRA_TEXT
• It’s required to pass type of
data being sent to the other
app.
• For eg. A simple piece of text is
sent using text/plain
• An image is sent using image/*
• A video is sent using video/*
• Create an Intent object
and specify the intent. (For
eg, ACTION_SEND)
An intent is a request for the system to perform some action, commonly presenting a new activity.
Create
Intent
Specify type
of data being
sent
Pass data
to Intent
Start the
Intent
• Call startActivity() method of
context.
• Context can be received using
LocalContext.current
This work is licensed under the Apache 2.0 License
POINTS TO NOTE:
 To make the app fully interactive, the APPBAR should also support
navigation functionality.
System back button provided by
Android operating system.
Up button, located in the app’s
Top Bar.
 Up button in the app’s top bar can be implemented properly using
currentBackStackEntry()
WHAT IS
BACKSTACK???
 When the app is first launched and displays it’s start destination, Navigation
Component creates a new BackStack to represent the navigation state of your
app.
 As soon as the app launches, the first screen’s instance is pushed to this
backstack
 As the user navigates to different screen, each screen keeps on adding in the
backstack, so that the previous screen can be displayed if the user hits on back
button on the bottom navigation bar.
This work is licensed under the Apache 2.0 License
BACKSTACK
THAT’s IT??
This work is licensed under
the Apache 2.0 License
Nope…,
Let’s go for the
Q&A SESSION…
THANK YOU!!!
This work is licensed under the Apache 2.0 License
GDSC-NSUT thanks you all for
your valuable time…
Signing off…

More Related Content

Similar to Android Student Guide

Google Compose Camp Session 3.pptx.pdf
Google Compose Camp Session 3.pptx.pdfGoogle Compose Camp Session 3.pptx.pdf
Google Compose Camp Session 3.pptx.pdfDhruv675089
 
Case study on tablet application for real time video, audio and ppt conversion
Case study on tablet application for real time video, audio and ppt conversionCase study on tablet application for real time video, audio and ppt conversion
Case study on tablet application for real time video, audio and ppt conversionGrey Matter India Technologies PVT LTD
 
How Android Architecture Components can Help You Improve Your App’s Design?
How Android Architecture Components can Help You Improve Your App’s Design?How Android Architecture Components can Help You Improve Your App’s Design?
How Android Architecture Components can Help You Improve Your App’s Design?Paul Cook
 
iOS Architectures
iOS ArchitecturesiOS Architectures
iOS ArchitecturesHung Hoang
 
Password security system for websites
Password security system for websitesPassword security system for websites
Password security system for websitesMike Taylor
 
Developing applications using Embedded Rich Client Platform (eRCP)
Developing applications using Embedded Rich Client Platform (eRCP)Developing applications using Embedded Rich Client Platform (eRCP)
Developing applications using Embedded Rich Client Platform (eRCP)Gorkem Ercan
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react jsStephieJohn
 
Everything to Know About React Re-Rendering: A Comprehensive Guide
Everything to Know About React Re-Rendering: A Comprehensive GuideEverything to Know About React Re-Rendering: A Comprehensive Guide
Everything to Know About React Re-Rendering: A Comprehensive GuideBOSC Tech Labs
 
Android Architecture Components
Android Architecture ComponentsAndroid Architecture Components
Android Architecture ComponentsDarshan Parikh
 
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...Akira Hatsune
 
Angular interview questions
Angular interview questionsAngular interview questions
Angular interview questionsGoa App
 
Case study on Movie Quiz App For IPhone and IPad – Facebook Enabled
Case study on Movie Quiz App For IPhone and IPad –  Facebook Enabled Case study on Movie Quiz App For IPhone and IPad –  Facebook Enabled
Case study on Movie Quiz App For IPhone and IPad – Facebook Enabled Grey Matter India Technologies PVT LTD
 
Introduction to React JS.pptx
Introduction to React JS.pptxIntroduction to React JS.pptx
Introduction to React JS.pptxSHAIKIRFAN715544
 
Introduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptxIntroduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptxSHAIKIRFAN715544
 
Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Dr. Ramkumar Lakshminarayanan
 

Similar to Android Student Guide (20)

Google Compose Camp Session 3.pptx.pdf
Google Compose Camp Session 3.pptx.pdfGoogle Compose Camp Session 3.pptx.pdf
Google Compose Camp Session 3.pptx.pdf
 
Case study on tablet application for real time video, audio and ppt conversion
Case study on tablet application for real time video, audio and ppt conversionCase study on tablet application for real time video, audio and ppt conversion
Case study on tablet application for real time video, audio and ppt conversion
 
How Android Architecture Components can Help You Improve Your App’s Design?
How Android Architecture Components can Help You Improve Your App’s Design?How Android Architecture Components can Help You Improve Your App’s Design?
How Android Architecture Components can Help You Improve Your App’s Design?
 
iOS Architectures
iOS ArchitecturesiOS Architectures
iOS Architectures
 
Introduction of Xcode
Introduction of XcodeIntroduction of Xcode
Introduction of Xcode
 
Password security system for websites
Password security system for websitesPassword security system for websites
Password security system for websites
 
Copy of React_JS_Notes.pdf
Copy of React_JS_Notes.pdfCopy of React_JS_Notes.pdf
Copy of React_JS_Notes.pdf
 
Developing applications using Embedded Rich Client Platform (eRCP)
Developing applications using Embedded Rich Client Platform (eRCP)Developing applications using Embedded Rich Client Platform (eRCP)
Developing applications using Embedded Rich Client Platform (eRCP)
 
ios basics
ios basicsios basics
ios basics
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
 
React-JS.pptx
React-JS.pptxReact-JS.pptx
React-JS.pptx
 
Everything to Know About React Re-Rendering: A Comprehensive Guide
Everything to Know About React Re-Rendering: A Comprehensive GuideEverything to Know About React Re-Rendering: A Comprehensive Guide
Everything to Know About React Re-Rendering: A Comprehensive Guide
 
Android Architecture Components
Android Architecture ComponentsAndroid Architecture Components
Android Architecture Components
 
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...
 
Angular interview questions
Angular interview questionsAngular interview questions
Angular interview questions
 
Case study on Movie Quiz App For IPhone and IPad – Facebook Enabled
Case study on Movie Quiz App For IPhone and IPad –  Facebook Enabled Case study on Movie Quiz App For IPhone and IPad –  Facebook Enabled
Case study on Movie Quiz App For IPhone and IPad – Facebook Enabled
 
Introduction to React JS.pptx
Introduction to React JS.pptxIntroduction to React JS.pptx
Introduction to React JS.pptx
 
Introduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptxIntroduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptx
 
Tech Talk on ReactJS
Tech Talk on ReactJSTech Talk on ReactJS
Tech Talk on ReactJS
 
Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3
 

Recently uploaded

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 

Recently uploaded (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 

Android Student Guide

  • 2. This work is licensed under the Apache 2.0 License Aneesh Gupta (2nd Year student in CSE Branch) WHO AM I ?  My tech stack –  Android  Flutter  JAVA, Kotlin, Dart, XML  Real Projects Experience -> Working in start-ups to accomplish real world problems.  Hobbies ->  Solving real problems
  • 3. First Android App Build App UI App architecture & Navigation Layouts, Lists & Material
  • 4. This work is licensed under the Apache 2.0 License ● Activity & Lifecycle ● What is Architecture & it’s Principles? ● Layers in Architecture ● What is Navigation? ● How to achieve Navigation? Today’s AGENDA…
  • 5. This work is licensed under the Apache 2.0 License  Faith-Based learning  Abstraction level of learning How to study DEVELOPMENT ?
  • 6. This work is licensed under the Apache 2.0 License ACTIVITY  Activity is the entry point for interacting with the user.  During it’s lifetime, it transitions through various states which is known as ACTIVITY LIFECYCLE.  Activity lifecycle extends from the creation of the activity to its destruction.  If an activity doesn’t respond correctly to lifecycle state changes, app can generate bugs, strange behavior and may consume too many Android resources.
  • 7. Activity Lifecycle onCreate() -> called when activity is first created. onStart() -> called when activity is visible to user. onResume() -> called when activity is interactable with the user onDestroy() -> called when activity is destroyed onStop() -> called when activity is no longer visible to the user onPause() -> called when activity is about to lose focus.
  • 8. This work is licensed under the Apache 2.0 License Hands-on on Activity Lifecycle (A small demo on how activity lifecycle callbacks work)
  • 9. This work is licensed under the Apache 2.0 License ARCHITECTURE  Designing pattern and techniques to construct the app to have a right structure to remain functional and safe under challenging conditions  Advantages –  Easier to Test  Makes App Robust  Easy to Collaborate  Makes App Scalable
  • 10. PRINCIPLES ()(Must be Followed) This work is licensed under the Apache 2.0 License SOC ()(Separation of Concern) Every component must have it’s own functionality and must not intervene with the logic of other components. For eg. UI components must know only about UI composables and should not know anything about the data to be presented in the UI. UDF ()(Unidirectional Flow) UI Components must ask the Data component for the data to be displayed on the screen and similarly, should expose any event / user interaction to the data component to update the data accordingly.
  • 11. This work is licensed under the Apache 2.0 License ● Activity’s lifecycle is tied to the Android Operating System. ● Change in configuration of the app results in creation of a new instance for the activity. ● If Data of the app is maintained within the activity, it might get lost and hence, we would loose the state of our app!! ● So, it’s important to separate all the app data and resources into such files which are independent of the Android framework. How to Apply ?? To achieve the same, we’ll now think of UI and Data as 2 separate layers  Data Layer - a layer that displays the app data on the screen but is independent of the data  UI Layer - a layer that stores, retrieves, and exposes the app data.
  • 12. This work is licensed under the Apache 2.0 License Hands-on on Activity Configuration Changes (How data is lost if stored in activity during configuration changes)
  • 13. WHAT IS STATE?  State in an app is any value that can change over time. • For eg. In a TextField, state is the TEXT that is being entered by the user. As soon as the user types in a new character, the state of the TextField (i.e. it’s text) is changed.  Compose is declarative and as such the only way to update it is by calling the same composable with new arguments. (i.e. a New State)  Any time a state is updated a recomposition takes place.  As a result, things like TextField don’t automatically update like they do in imperative XML based views. A composable has to explicitly be told the new state in order for it to update accordingly. This work is licensed under the Apache 2.0 License UI is what user sees, BUT UI State is what the app says they should see… UI is a result of binding UI elements on the screen with UI state…
  • 14. This work is licensed under the Apache 2.0 License NEED OF UDF  If code in both layers hold refence of each other and there’s no unidirectional flow, then there’s no Separation of Concern.  There must be flow of data in the following manner ->  UI exposes events to Data.  Data changes and updates are observed by UI. Data Layer UI Layer Data Layer UI Layer Events Data Hence, Unidirectional Flow is important, else would lead to Data dependency on Android Framework
  • 15. Layers of UI  UI Layer has 2 components – • UI Elements (Composables) • State Holders (ViewModel)  ViewModel holds and exposes state that the UI elements consume.  It stores the app related data that isn’t destroyed when the activity is destroyed and recreated by Android Framework  Unlike the activity instance, ViewModel objects are not destroyed on configuration change  This frees up the UI and make it focus solely on to read and update the UI elements accordingly. This work is licensed under the Apache 2.0 License
  • 16. This work is licensed under the Apache 2.0 License How to implement ViewModel? StateFlow It’s a data holder observable flow that emits the current and new state updates. (In our eg, the new UI State) To update state and send it to the flow, assign a new value to the value property of the Mutable State Flow class. It can be exposed from the new UI State, so that the composables can listen for UI updates and make screen state survive configuration changes. Backing Property A backing property lets you return something from a getter other than the exact object. To implement a backing property, you override the getter method to return a read-only version of your data. This backing property protects the app data inside the ViewModel from unwanted and unsafe changes by external classes, but it lets external callers safely access its value. Before we proceed, we need to understand the following terms ->
  • 17. This work is licensed under the Apache 2.0 License Hands-on on ViewModel (What do you need to know to implement a ViewModel)
  • 18. This work is licensed under the Apache 2.0 License Create UIState Create GameUIState data class consisting of the different state components of the app which will be exposed to UI by ViewModel to make updates in UI Get Current State of the App Use asStateFlow() on a mutableStateFlow instance (i.e. GameUIState instance here) to implement Backing property on UI State. Get Random word to be displayed Implement a new function to get unused random word. Summarizing UnScramble App Create ViewModel Create a GameViewModel extending ViewModel class ViewModel in Composable Instantiate ViewModel in Parent Composable. Get State in Composable from ViewModel Use collectAsState() to obtain new UiState from ViewModel Pass Lambda Expressions for events ViewModel receives the events via lambda expressions and update UIState accordingly which is then observed by the mutableStateFlow instance in Composable. Handle Last Round As soon as the size of set containing usedWords becomes equal to 10, show a popup, to the user, in which if Play Again is selected, reset the game, else finish the activity.
  • 19. Let’s try change in device configuration… You’ll observe that when the device is rotated, though activity gets destroyed and is being created again by the Android Operating System, but the state of the app doesn’t change. This is because ViewModel’s instance doesn’t get cleared off and therefore the new Composables so formed get their data to be displayed from the state stored with ViewModel.
  • 20. This work is licensed under the Apache 2.0 License ViewModel is a life-saver for change in configurations…
  • 21. This work is licensed under the Apache 2.0 License NAVIGATION…  Till Now, you saw Single Screen Apps in all our session. But now, let’s deep dive into Multi-Screen Apps.  Navigation Compose Component allows you to build multiscreen apps in Compose using a declarative approach.  You’ll also get to know how to send data from your app to another using intents.
  • 22. This work is licensed under the Apache 2.0 License ● NavController : Used to navigate b/w destinations (screens of the app) ● NavGraph : Maps composable destinations ● NavHost : Composable Container for displaying current destination Parts of Navigation Component
  • 23. This work is licensed under the Apache 2.0 License ( How to properly implement Navigation in multi-screen app while we respect the architecture principles such as SOC ) Hands-on on Navigation
  • 24. This work is licensed under the Apache 2.0 License Steps to achieve Navigation 2 3 5 4 1 Define Routes • Route -> A string corresponding to a specific destination. • Route is a unique identifier for a destination. • HOW TO DEFINE ONE -> Using Enum classes Initialize NavHost • Displays a specific screen on the basis of route selected. • Mandatory arguments -> NavController & StartDestination (first screen to be shown by default) Understanding NavController • NavHostController instance helps to navigate to different screens using navigate() function. • Obtained by calling rememberNavController() Handle Routes • Navhost takes composable() function as it’s content. • For each screen, a separate composable() is required which consists of route name and the Composable to be displayed. Respect Architecture • We can’t pass NavController as a parameter to every screen to handle navigation. (Each screen should not be aware of any other screen) • Hence, we pass a function type in each composable to handle the navigation.
  • 25. This work is licensed under the Apache 2.0 License  Sometimes, we have to send some data from our app to another app (For eg. while making payments, the app usually navigates us to some other payment-making app).  Since, this functionality is provided by the Android Operating System, we don’t use NavController, but something called an INTENT. Navigating to Another App
  • 26. This work is licensed under the Apache 2.0 License Steps to achieve Navigation to Another App • Pass any additional data to intent by using putExtra() method. • Intent takes 2 extras -> EXTRA_SUBJECT & EXTRA_TEXT • It’s required to pass type of data being sent to the other app. • For eg. A simple piece of text is sent using text/plain • An image is sent using image/* • A video is sent using video/* • Create an Intent object and specify the intent. (For eg, ACTION_SEND) An intent is a request for the system to perform some action, commonly presenting a new activity. Create Intent Specify type of data being sent Pass data to Intent Start the Intent • Call startActivity() method of context. • Context can be received using LocalContext.current
  • 27. This work is licensed under the Apache 2.0 License POINTS TO NOTE:  To make the app fully interactive, the APPBAR should also support navigation functionality. System back button provided by Android operating system. Up button, located in the app’s Top Bar.  Up button in the app’s top bar can be implemented properly using currentBackStackEntry()
  • 28. WHAT IS BACKSTACK???  When the app is first launched and displays it’s start destination, Navigation Component creates a new BackStack to represent the navigation state of your app.  As soon as the app launches, the first screen’s instance is pushed to this backstack  As the user navigates to different screen, each screen keeps on adding in the backstack, so that the previous screen can be displayed if the user hits on back button on the bottom navigation bar.
  • 29. This work is licensed under the Apache 2.0 License BACKSTACK
  • 30. THAT’s IT?? This work is licensed under the Apache 2.0 License Nope…, Let’s go for the Q&A SESSION…
  • 31. THANK YOU!!! This work is licensed under the Apache 2.0 License GDSC-NSUT thanks you all for your valuable time… Signing off…