Jetpack is a suite of libraries and architecture components that help developers follow best practices to reduce boilerplate code and write code that is compatible across Android versions and devices. It includes libraries for UI components, navigation, data binding, room, lifecycle management, and more. Using Jetpack can help developers focus on the code that matters by eliminating redundant code and ensuring compatibility.
3. Curriculum Developer at DICODING
Write and compile Industry-verified "Android and iOS
Development" e-learning material. In addition, I act as a
mentor for Dicoding Academy participants.
Nov 2018 - Now
Android Trainer and Developer at IMASTUDIO
Teaching participants/students to be able to make Android
applications with training models for 4-5 days full-time. Starting
from the basic understanding of Android to Intermediate.
Oct 2015 - Dec 2017
Intern Android Developer at GOJEK
Responsible for developing the Android application "GoLife
Partners".
Feb 2018 - Mei 2018
4. Android Jetpack
Jetpack is a suite of libraries to help
developers follow best practices, reduce
boilerplate code, and write code that
works consistently across Android
versions and devices.
So that developers can focus on the code
they care about.
5. Why use Android Jetpack?
Follow best practices
Built around modern design practices,
Android Jetpack Libraries enable fewer
crashes and less memory leaks with
backwards-compatibility baked in.
6. Review Case Study
iHeartRadio creates a cleaner, leaner code base with
Android Architecture Components.
https://developer.android.com/stories/apps/iheartradio
7. Why use Android Jetpack?
Eliminate boilerplate code
Android Jetpack manages tedious activities
like background tasks, navigation, and
lifecycle management, so you can focus on
what makes your app great.
8. Review Case Study
Monzo reduced over 9,000 lines of code and improved
registration dropout by 5x with CameraX.
https://developer.android.com/stories/apps/monzo-camerax
9. Why use Android Jetpack?
Reduce fragmentation
Reduce complexity with libraries that work
consistently across Android versions and
devices.
10. Testimoni
"With Android Architecture Components,
we're re-architecting our entire app. It's
great to have a Google-endorsed,
opinionated, and clean way to build an
Android app that makes it easier to
support configuration changes."
Drew Hannay, Staff Software Engineer, LinkedIn
11. Testimonial
"Room made it really easy for us to create
the database table and DAO so we could
quickly build our product. And the
emphasis on testability is critical for us."
Demian Insung Hwang, KakaoTalk Developer,
KakaoTalk
12. History of Jetpack
In 2018, Google launched Android
Jetpack. 47% of the top 1000 apps use 2
or more Jetpack libraries, not including
core libraries like AppCompat or
Lifecycle.
15. Beyond phones
● car
Develop driving-friendly applications for an Android-powered car.
● slice
Display templated UI elements outside your app.
● tvprovider
Provide Android TV channels.
● wear
Create applications for Wear OS by Google smartwatches.
● window
Helps support different device form factors such as foldable devices.
16. Car
Bring your app to vehicles running either Android
Auto or Android Automotive OS. Use one app
architecture that works for both cases so every user
can enjoy your app.
17. Slice
Slices are UI templates that can display rich, dynamic, and
interactive content from your app from within the Google
Search app and also in other places like the Google
Assistant.
Slices can help users perform tasks faster by enabling
engagement outside of the fullscreen app experience. You
can build Slices as enhancements to App Actions.
Support for Slices is built into Android Jetpack and can
extend all the way back to Android 4.4, reaching
approximately 95% of all Android users.
18. Tv Provider
The TV Provider database stores the channels
and programs from TV Inputs. The TV Provider
also publishes and manages the associated
permissions so that TV Inputs can see only
their own records.
For instance, a specific TV Input can see only
the channels and programs it has supplied and
is prohibited from accessing any other TV
Inputs’ channels and programs.
19. Wear OS by Google
Make every minute matter with Wear OS by Google. Smartwatches
that keep you connected to your health, the people and info you
care about, and your Google Assistant — all from your wrist.
20. Window Manager
The Android WindowManager is a
system service, which is responsible for
managing the z-ordered list of
windows, which windows are visible,
and how they are laid out on screen.
Among other things, it automatically
performs window transitions and
animations when opening or closing an
app or rotating the screen.
21. Data
● datastore
Store data asynchronously, consistently, and transactionally, overcoming some of the drawbacks of
SharedPreferences.
● paging*
Load data in pages, and present it in a RecyclerView.
● preference
Build interactive settings screens without needing to interact with device storage or manage the UI.
● room*
Create, store, and manage persistent data backed by a SQLite database.
● sqlite
Work with local SQLite databases. If possible, use Room instead.
● work*
Schedule and execute deferrable, constraint-based background tasks.
* Popular and often-used library
22. Preference
Settings allow users to change the
functionality and behavior of an application.
Settings can affect background behavior,
such as how often the application
synchronizes data with the cloud, or they
can be more wide-reaching, such as
changing the contents and presentation of
the user interface.
23. Data Store
Jetpack DataStore is a data storage solution that allows you to store key-value
pairs or typed objects with protocol buffers. DataStore uses Kotlin coroutines
and Flow to store data asynchronously, consistently, and transactionally.
If you're currently using SharedPreferences to store data, consider migrating
to DataStore instead.
24. Sqlite
Saving data to a database is ideal for repeating or
structured data, such as contact information.
This page assumes that you are familiar with SQL
databases in general and helps you get started with
SQLite databases on Android.
The APIs you'll need to use a database on Android are
available in the android.database.sqlite package.
25. Room
Room provides an abstraction layer over SQLite to
allow fluent database access while harnessing the
full power of SQLite.
● Database: Contains the database holder and serves
as the main access point for the underlying
connection to your app's persisted, relational data.
● Entity: Represents a table within the database.
● DAO: Contains the methods used for accessing the
database.
26. Paging
The Paging Library helps you load and
display small chunks of data at a time.
Loading partial data on demand reduces
usage of network bandwidth and system
resources.
27. Work Manager
WorkManager is an API that makes it easy to
schedule deferrable, asynchronous tasks that are
expected to run even if the app exits or the device
restarts.
The WorkManager API is a suitable and
recommended replacement for all previous Android
background scheduling APIs, including
FirebaseJobDispatcher, GcmNetworkManager, and
Job Scheduler.
WorkManager incorporates the features of its
predecessors in a modern, consistent API that works
back to API level 14 while also being conscious of
battery life.
28. Graphics
● core
The core.animation package supports many common animation functions.
● dynamicanimation
Create smooth animations with a physics-based animation API.
● interpolator
Use animation interpolators on older platforms.
● palette
Extract representative color palettes from images.
● transition
Animate motion in the UI with starting and ending layouts.
● vectordrawable
Render vector graphics.
* Popular and often-used library
29. Core Animation
The core.animation package supports many common
animation functions.
Animations can add visual cues that notify users about
what's going on in your app.
They are especially useful when the UI changes state,
such as when new content loads or new actions become
available. Animations also add a polished look to your
app, which gives it a higher quality look and feel.
30. Dynamic Animation
Physics-based motion is driven by force. Spring force is one
such force that guides interactivity and motion. A spring
force has the following properties: damping and stiffness. In
a spring-based animation, the value and the velocity are
calculated based on the spring force that are applied on each
frame.
If you'd like your app's animations to slow down in only one
direction, consider using a friction-based fling animation
instead.
31. Interpolator
An interpolator define how specific values in an animation
are calculated as a function of time. For example, you can
specify animations to happen linearly across the whole
animation, meaning the animation moves evenly the entire
time, or you can specify animations to use non-linear time,
for example, using acceleration or deceleration at the
beginning or end of the animation.
https://medium.com/mindorks/understanding-interpolators-in-android-ce4e8d1d71cd
33. Transition
The Navigation component lets you add both property and view animations
to actions. To create your own animations, check out Animation resources.
34. Vector Drawable
A VectorDrawable is a vector graphic defined in an XML
file as a set of points, lines, and curves along with its
associated color information.
The major advantage of using a vector drawable is image
scalability. It can be scaled without loss of display quality,
which means the same file is resized for different screen
densities without loss of image quality.
This results in smaller APK files and less developer
maintenance. You can also use vector images for
animation by using multiple XML files instead of multiple
images for each display resolution.
35. Lifecycle
● lifecycle*
Build lifecycle-aware components that can adjust behavior based on
the current lifecycle state of an activity or fragment.
● loader
Load data for your UI that survives configuration changes.
* Popular and often-used library
36. Lifecycle
Lifecycle-aware components perform actions in response to a change in the lifecycle status of
another component, such as activities and fragments. These components help you produce
better-organized, and often lighter-weight code, that is easier to maintain.
37. Loader
Loaders have been deprecated as of Android P (API 28). The recommended option for dealing
with loading data while handling the Activity and Fragment lifecycles is to use a combination
of ViewModels and LiveData.
38. Media
● camera*
Build mobile camera apps.
● exifinterface
Read and write image file EXIF tags.
● heifwriter
Encode an image or image collection in HEIF format using the available codecs on the Android
device.
● media
Share media contents and controls with other apps. Superseded by media2.
● media2
Share media contents and controls with other apps.
● mediarouter
Enable media display and playback on remote receiver devices using a common user interface.
* Popular and often-used library
39. CameraX
CameraX is a Jetpack support library, built to help you
make camera app development easier. It provides a
consistent and easy-to-use API surface that works
across most Android devices, with
backward-compatibility to Android 5.0 (API level 21).
● Ease of use
● Consistency across devices
● New camera experiences
● Case study
40. Media2
This section explains how to separate a media player app
into a media controller (for the UI) and a media session
(for the actual player).
It describes two media app architectures: a client/server
design that works well for audio apps and a single-activity
design for video players. It also shows how to make media
apps respond to hardware controls and cooperate with
other apps that use the audio output stream.
41. Media Router
In order to use the MediaRouter framework within your app, you
must get an instance of the MediaRouter object and attach a
MediaRouter.Callback object to listen for routing events.
Content sent over a media route passes through the route's
associated MediaRouteProvider (except in a few special cases,
such as a Bluetooth output device). Figure 1 provides a
high-level view of the classes used to route content between
devices.
42. Navigation
● core
The core.animation package supports many common animation
functions.
● drawerlayout
Implement a Material Design drawer widget.
● navigation*
Build and structure your in-app UI, handle deep links, and navigate
between screens.
● transition
Animate motion in the UI with starting and ending layouts.
* Popular and often-used library
43. Drawer Layout
The navigation drawer is a UI panel that shows your
app's main navigation menu. The drawer appears when
the user touches the drawer icon in the app bar or
when the user swipes a finger from the left edge of the
screen.
44. Navigation
Navigation refers to the interactions that allow users
to navigate across, into, and back out from the
different pieces of content within your app. Android
Jetpack's Navigation component helps you implement
navigation, from simple button clicks to more complex
patterns, such as app bars and the navigation drawer.
45. Security
● biometric
Authenticate with biometrics or device credentials, and perform
cryptographic operations.
● core
Target the latest platform features and APIs while also supporting older
devices.
● security
Safely manage keys and encrypt files and sharedpreferences.
* Popular and often-used library
46. Biometry
One method of protecting sensitive information or
premium content within your app is to request
biometric authentication, such as using face
recognition or fingerprint recognition.
This guide explains how to support biometric login
flows in your app.
47. Performance/Test
● benchmark
Accurately measure your code's performance within Android Studio.
● startup
Implement a straightforward, performant way to initialize components at
app startup.
● test*
Testing in Android.
● tracing
Write trace events to the system trace buffer.
* Popular and often-used library
48. Test
Testing your app is an integral part of the app development
process. By running tests against your app consistently, you
can verify your app's correctness, functional behavior, and
usability before you release it publicly.
Testing also provides you with the following advantages:
● Rapid feedback on failures.
● Early failure detection in the development cycle.
● Safer code refactoring, letting you optimize code
without worrying about regressions.
● Stable development velocity, helping you minimize
technical debt.
49. UI
● appcompat*
Allows access to new APIs on older API versions of the platform (many using Material
Design).
● cardview
Implement the Material Design card pattern with round corners and drop shadows.
● compose*
Define your UI programmatically with composable functions that describe its shape and
data dependencies.
● constraintlayout
Position and size widgets in a flexible way with relative positioning.
● coordinatorlayout
Position top-level application widgets, such as AppBarLayout and FloatingActionButton.
* Popular and often-used library
50. Jetpack Compose
Build better apps faster with Jetpack Compose.
Jetpack Compose is Android’s modern toolkit for
building native UI. It simplifies and accelerates UI
development on Android. Quickly bring your app to life
with less code, powerful tools, and intuitive Kotlin
APIs.
51. UI
● customview
Implement custom views.
● databinding *
Bind UI components in your layouts to data sources in your app using a
declarative format.
● emoji
Display emoji in current and older devices.
● fragment *
Segment your app into multiple, independent screens that are hosted within
an Activity.
● gridlayout
Implement a grid layout.
* Popular and often-used library
52. Data Binding
The Data Binding Library is a support library that allows you to bind UI components in
your layouts to data sources in your app using a declarative format rather than
programmatically.
Layouts are often defined in activities with code that calls UI framework methods. For
example, the code below calls findViewById() to find a TextView widget and bind it to
the userName property of the viewModel variable:
53. Emoji
The EmojiCompat support library aims to keep
Android devices up to date with the latest emoji.
It prevents your app from showing missing emoji
characters in the form of ☐, which indicates that
your device does not have a font to display the
text.
By using the EmojiCompat support library, your
app users do not need to wait for Android OS
updates to get the latest emoji.
54. Fragment
A Fragment represents a reusable portion of your
app's UI. A fragment defines and manages its
own layout, has its own lifecycle, and can handle
its own input events.
Fragments cannot live on their own--they must
be hosted by an activity or another fragment. The
fragment’s view hierarchy becomes part of, or
attaches to, the host’s view hierarchy.
55. UI
● Material Design Components*
Modular and customizable Material Design UI components for Android.
● paging*
Load data in pages, and present it in a RecyclerView.
● palette
Extract representative color palettes from images.
● recyclerview
Display large sets of data in your UI while minimizing memory usage.
● slice
Display templated UI elements outside your app.
* Popular and often-used library
56. Material Design Components
Modular and customizable Material Design UI
components for Android.
Build beautiful, usable products using Material
Components for Android
57. UI
● slidingpanelayout
Implement a sliding pane UI pattern.
● swiperefreshlayout
Implement the swipe-to-refresh UI pattern.
● viewpager
Display Views or Fragments in a swipeable format. If possible, use viewpager2
instead.
● viewpager2
Display Views or Fragments in a swipeable format.
● webkit
Work with modern WebView APIs on Android 5 and above.
* Popular and often-used library
58. Other Popular Library..
● activity *
Access composable APIs built on top of Activity.
● hilt *
Extend the functionality of Dagger Hilt to enable dependency injection of
certain classes from the androidx libraries.
* Popular and often-used library
59. Activity
The Activity class is a crucial component of
an Android app, and the way activities are
launched and put together is a fundamental
part of the platform's application model.
Unlike programming paradigms in which
apps are launched with a main() method,
the Android system initiates code in an
Activity instance by invoking specific
callback methods that correspond to
specific stages of its lifecycle.
60. Hilt
Hilt is a dependency injection library for
Android that reduces the boilerplate of
doing manual dependency injection in your
project. Doing manual dependency injection
requires you to construct every class and its
dependencies by hand, and to use
containers to reuse and manage
dependencies.
61. And Another Library...
● ads
Get an advertising ID with or without Play Services.
● multidex
Deploy applications with multiple dex files on pre-Android 5 devices.
● more….
* Popular and often-used library
62. Ads
To protect user privacy, it's a best practice
for all Android apps to work with
user-resettable identifiers.
One such identifier is an advertising ID,
which uniquely identifies a particular user
for advertising use cases, such as ad
personalization.
64. Ingat! Fokus!
Kuncinya adalah Fokus. Coba fokus
menggunakan satu atau beberapa library terlebih
dahulu. Contohnya library-library popular seperti:
● Activity
● Appcompat
● Camera
● Compose
● Databinding
● Fragment
● Hilt
● Lifecycle
● Material Design Components
● Avigation
● Paging
● Room
● Test
● Work
65. Learn to use Jetpack
Fundamentals Training
Learn the essential Jetpack libraries in
the Android Kotlin Fundamentals Course
and reduce boilerplate in your app.
66. Android Kotlin Fundamentals
Lesson 1: Build your first app
Lesson 2: Layouts
Lesson 3: Navigation
Lesson 4: Activity and fragment lifecycles
Lesson 5: Architecture components
Lesson 6: Room database and coroutines
Lesson 7: RecyclerView
Lesson 8: Connecting to the internet
Lesson 9: Repository
Lesson 10: Designing for everyone
https://developer.android.com/courses
/kotlin-android-fundamentals/overview
67. Learn to use Jetpack
Hands-on Tutorial
Get hands-on with three Jetpack libraries that
simplify your data layer: LiveData, ViewModel
and Room
68. Android Room with a View - Kotlin
● Implements our recommended architecture using the
Android Architecture Components.
● Works with a database to get and save the data, and
pre-populates the database with some sample words.
● Displays all the words in a RecyclerView in the
MainActivity class.
● Opens a second activity when the user taps the +
button. When the user enters a word, that word is
added to the database and displayed in the
RecyclerView list.
70. Entity: Annotated class that describes a database table when working with Room.
SQLite database: On device storage. The Room persistence library creates and maintains this database for you.
DAO: Data access object. A mapping of SQL queries to functions. When you use a DAO, you call the methods,
and Room takes care of the rest.
Room database: Simplifies database work and serves as an access point to the underlying SQLite database
(hides SQLiteOpenHelper). The Room database uses the DAO to issue queries to the SQLite database.
Repository: A class that you create that is primarily used to manage multiple data sources.
ViewModel: Acts as a communication center between the Repository (data) and the UI. The UI no longer needs
to worry about the origin of the data. ViewModel instances survive Activity/Fragment recreation.
LiveData: A data holder class that can be observed. Always holds/caches the latest version of data, and notifies
its observers when data has changed. LiveData is lifecycle aware. UI components just observe relevant data and
don't stop or resume observation. LiveData automatically manages all of this since it's aware of the relevant
lifecycle status changes while observing.
Architecture Components
71. Learn to use Jetpack
Sunflower Sample App
Explore how the most popular Jetpack
libraries are used together in a
production-level app
74. Using Jetpack components
● Sunflower is written entirely in Kotlin, using Android KTX. Android
KTX is a set of Kotlin extensions that optimizes Jetpack and
Android platform APIs for more concise and idiomatic Kotlin code.
● The app uses a single Activity with multiple Fragments.
Transitions between fragments use the Navigation component and
transition animation actions.
● The screens use fragment layouts, created using ConstraintLayout
and Data Binding.
● On-device data storage of the plant list and my garden entries are
managed with Room at the database level, and surfaced to the UI
through ViewModels via LiveData.
75. Using Jetpack components
● AppCompat is used to preserve key app functionality on
older versions of Android.
● Background tasks are handled by WorkManager.
● Plant details can be shared with other applications on the
device, or simply copied to the clipboard.
● Testing is performed by both local JUnit tests and
Espresso Android UI tests.
76. Check out the code for Sunflower
https://github.com/googlesamples/android-sunflower
77. https://www.dicoding.com/learningpaths/
7
Kurikulum didesain oleh Dicoding sebagai
satu-satunya Google Developers Authorized
Training Partner di Indonesia. Siswa dipersiapkan
untuk menjadi Android Developer berstandar
global Google.
● Memulai Pemrograman Dengan Kotlin
● Belajar Prinsip Pemrograman SOLID
● Belajar Prinsip Pemrograman Belajar Membuat
Aplikasi Android untuk Pemula
● Belajar Fundamental Aplikasi Android
● Belajar Android Jetpack Pro
● Menjadi Android Developer Expert
Android Developer
dicoding.com/learningpaths/7
78. Bonus...
● Hilt
Extend the functionality of Dagger Hilt to enable
dependency injection of certain classes from the
androidx libraries.
● Compose
Define your UI programmatically with
composable functions that describe its shape
and data dependencies.
79. Hilt
Hilt is a dependency injection library for
Android that reduces the boilerplate of
doing manual dependency injection in your
project. Doing manual dependency injection
requires you to construct every class and its
dependencies by hand, and to use
containers to reuse and manage
dependencies.
80. Hilt Android
2012
Dagger 1.0
A fast dependency injector
for Android and Java. Create
by Square.
https://square.github.io/dagger/
Dagger 2.0
Move Repository from
Square to Google.
https://github.com/google/dagg
er/releases/tag/dagger-2.0
2016
Hilt
Hilt provides a standard
way to incorporate Dagger
dependency injection into
an Android application.
https://dagger.dev/hilt/
2020
81. The goals of Hilt are:
● To simplify Dagger-related infrastructure for
Android apps.
● To create a standard set of components and
scopes to ease setup,
readability/understanding, and code sharing
between apps.
● To provide an easy way to provision different
bindings to various build types (e.g. testing,
debug, or release
83. Jetpack Compose
Build better apps faster with Jetpack Compose.
Jetpack Compose is Android’s modern toolkit for
building native UI. It simplifies and accelerates UI
development on Android. Quickly bring your app to life
with less code, powerful tools, and intuitive Kotlin
APIs.
84. Jetpack Compose
Less code Intuitive Accelerate Development Powerful
Do more with less code
and avoid entire classes
of bugs, so code is simple
and easy to maintain.
Just describe your UI,
and Compose takes care
of the rest. As app state
changes, your UI
automatically updates.
Compatible with all your existing
code so you can adopt when and
where you want. Iterate fast with
live previews and full Android
Studio support.
Create beautiful apps with direct
access to the Android platform
APIs and built-in support for
Material Design, Dark theme,
animations, and more.
87. Jetpack Compose Pathway
1. Tutorial: Compose Basics
2. Thinking in Compose
3. Compose Mental Model
4. Compose basics
5. Compose by Example
6. Layouts in Compose
7. Using State in Compose
8. Compose Theming
9. Compose for Existing Apps
10. Migrating to Compose
https://developer.android.com/courses/kotlin-android-fundamentals/overview
88. Note
Jetpack Compose is currently in Developer
Preview. The API surface is not yet finalized, and
changes are planned and expected.
Versi 1.0.0-alpha07 (November 11, 2020)
89. Try it!
Jetpack Compose Basics Codelab
https://codelabs.developers.google.com/codelabs/jetpack-compose-basics
Android’s Modern Toolkit for Building Native UI
https://developer.android.com/jetpack/compose
Jetpack Compose Tutorial for Android: Getting Started
https://www.raywenderlich.com/7032631-jetpack-compose-tutorial-for-android-getting-started
Jetpack Compose Basics Tutorial
https://developer.android.com/jetpack/compose/tutorial