Styles
Definition: "Style" refers to the way something is presented. It could be the way
something looks (design) or the way something is written (writing).
Types:Writing Styles:
o Formal: Uses full sentences and proper grammar (e.g., academic papers).
o Informal: More relaxed and conversational (e.g., blogs).
Design Styles:
o Modern: Simple, clean, and sleek designs.
o Vintage: Old-school, nostalgic designs.
o Minimalist: Simple, without many elements, focusing on what’s most important.
o Grunge: Rough, edgy, and dark designs.
Themes
Definition: A theme is the main idea or subject of something, like a story or a design. It’s
what the content or design is about.
Types:In Writing:
o Love: Focuses on romantic relationships (e.g., “Romeo and Juliet”).
o Friendship: Focuses on friendships (e.g., “Harry Potter”).
o Adventure: Focuses on a journey (e.g., “Lord of the Rings”).
In Design:
o Nature: Earthy colors and natural elements.
o Retro: Designs that remind you of the past.
o Futuristic: Modern designs with technology.
o Minimalist: Clean and simple.
Material Design
Definition: Material Design is a set of rules from Google to make apps and websites look
modern, easy to use, and consistent. It uses shadows, grids, and animations to make
things feel real (like objects in the physical world).
Key Concepts:
1. Typography: Choosing readable fonts to make text easy to understand.
o Example: Google uses a font called Roboto in apps.
2. Color Palette: Using colors that look good together and have enough contrast.
o Example: Primary colors for buttons, and secondary colors for highlights.
3. Layout: Organizing everything on the screen in a clean, balanced way.
4. Components: Ready-made parts like buttons, text fields, or menus that you can use in
your design.
5. Motion and Animations: Animations guide users, making the app feel more interactive.
o Example: Buttons changing colors when clicked.
6. Elevation and Shadows: Shadows create depth, helping you see what is clickable or
interactive.
7. Icons: Simple images that represent actions or ideas (e.g., a pencil icon for editing).
8. Responsive Design: Making sure your app looks good on all screen sizes.
9. Accessibility: Making sure people with disabilities can also use your app (e.g., adding
high contrast text for people who can’t see well).
Offline Cache & Repository
Definition: This is a way to store data on a device so it can be used even when there’s no
internet connection.
1. Offline Cache: Storing data on the device, so it’s available when offline.
o Example: In a messaging app, you can still read previous messages without the
internet.
o Types:
Memory Cache: Temporary data stored in RAM (lost when the app
closes).
Disk Cache: Data stored in storage (saved even after the app closes).
2. Repository: A system that manages storing and getting data from different sources,
whether online or offline.
o Example: A weather app might get data from the internet when online, but use
stored data when offline.
How to Implement:
Store data in cache when online.
Use cached data when offline.
Sync data with the server when the internet is back.
Benefits:
Faster Access: Cached data loads faster.
Offline Access: Users can still use the app without the internet.
Reduced Load: Less need to always talk to the server.
Work Manager
Definition: Work Manager helps you manage tasks that need to run in the background,
even if the app is closed or the phone restarts.
1. Work Types:
o One-time Work: Tasks that run once, like syncing data when the app starts.
o Periodic Work: Tasks that run repeatedly, like checking for updates every hour.
2. Work Request: A request for a task to be done, which specifies when and how it should
run.
o Example: A task that downloads files when connected to Wi-Fi.
3. Constraints: Conditions that must be met for the task to run (e.g., device must be
charging or connected to Wi-Fi).
o Example: Uploading files only when the phone is connected to Wi-Fi.
4. Worker Class: A class that contains the task to be done (e.g., download a file).
Benefits:
Reliability: Tasks will run even if the app is closed or the device restarts.
Battery Efficiency: Only run tasks when the device is charging or idle.
Flexible: Supports one-time or repeating tasks with specific conditions.
Background Workers:
Definition: A background worker is a process that runs behind the scenes in an application, handling
tasks without disturbing the main user interface (UI).
Types of Background Workers: 1: Threading: Allows multiple tasks to run concurrently (e.g.,
downloading a file while playing music). 2: Async Task: Used in apps to handle long-running tasks
asynchronously so the main UI remains responsive. 3: Service Workers: In web development, service
workers handle background tasks such as push notifications or caching for offline use
Periodic Worker Requests:
Definition: These are tasks scheduled to run repeatedly at specified intervals, such as sending
notifications, syncing data, or checking for updates.
Types of Periodic Worker Requests: 1: Time-based (Fixed interval): Tasks are triggered after a specific
time (e.g., every 15 minutes). 2: Interval-based (Flexible): Tasks run at intervals based on certain
conditions, such as when the user is idle or connected to Wi-Fi. 3:One-off periodic: Tasks that are
repeated once, usually to be triggered in a sequence (e.g., sending reminders every day at 9 AM).
Unit 4- Connecting to a Web Service with Retrofit Library
What is Retrofit?
Retrofit is a tool for Android and Java that makes it easy to connect your app to the internet and
get data from websites (APIs). Think of it like a bridge between your app and the internet.
How does Retrofit work?
You define an interface (kind of like a blueprint) to tell Retrofit what information you want.
Retrofit then connects to the internet, gets the data, and converts it into a format you can use in
your app (like turning a response from a website into Java objects).
How to use Retrofit or Steps to Use Retrofit
1.Add Retrofit to your project:
To get Retrofit, you need to add it to your project using these lines in your build.gradle file:
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
2 . Define the API Interface:
You create an interface with methods that match the actions you want to do. For example, to get user
data from a website:
public interface ApiService {
@GET("users/{id}")
Call<User> getUser(@Path("id") int userId); }
3.Create a Retrofit instance:
Set up Retrofit to know where to get the data from:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.example.com/")
.addConverterFactory(GsonConverterFactory.create())
.build();
ApiService apiService = retrofit.create(ApiService.class);
4. Make a request:
Then, call the method to get the data:
Call<User> call = apiService.getUser(1);
call.enqueue(new Callback<User>() { @Override
public void onResponse(Call<User> call, Response<User> response) {
if (response.isSuccessful()) {
User user = response.body(); } }@Override
public void onFailure(Call<User> call, Throwable t) {
// Handle errors }});
Types of requests:
1. GET: Get data from a website. 2. PUT: Update existing data on a website
3 .POST: Send data to a website..4.DELETE: Remove data from a website.
Unit -3 Loading and Displaying Images from the Internet
What does it mean to load and display images from the internet?
It means downloading images from a URL and showing them in your app’s UI (like in
an ImageView).
Why is it important?
It helps reduce memory usage and speeds up the app by caching images (storing them
temporarily on the device) so they don’t have to be downloaded again. It also ensures
images load smoothly without freezing the app.
How to use libraries like Glide and Picasso:
1. Glide Example:
1. Add Glide to your project:
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
2. Load the image:
Glide.with(context)
.load("https://example.com/image.jpg")
.into(imageView);
2. Picasso Example:
1. Add Picasso to your project:
implementation 'com.squareup.picasso:picasso:2.71828'
2.Load the image:
Picasso.get()
.load("https://example.com/image.jpg")
.into(imageView);
5. Filtering Data from the Internet
What does it mean to filter data from the internet?
It means selecting only the information you want, out of a large amount of data. For example, if you're
looking for recipes, filtering would show only vegetarian recipes and hide non-vegetarian ones.
Types of filters:
Keyword-based Filtering: Search for specific words or phrases.
Category-based Filtering: Filter by things like "Clothing" or "Electronics."
Date-based Filtering: Filter by time, like news from the past week.
Location-based Filtering: Filter by where something is, like nearby restaurants.
Price-based Filtering: Filter by price range, like showing only products that cost between $20
and $50.
Rating-based Filtering: Filter by ratings, like showing only products with a 4-star rating.
Boolean Filtering: Combine search terms, like searching for "cars AND electric."
Advanced Filtering: Complex filters, like finding "remote jobs in Java with a salary range of
$50,000 to $80,000."
Activity and Fragment Lifecycle
Activity Lifecycle: An activity is a screen in an Android app, and it goes through different stages.
These stages are like the steps it takes from the time it opens to when it closes.
1. onCreate(): Happens when the activity starts. It's where things are set up.
2. onStart(): Happens when the activity is visible but not yet interactive.
3. onResume(): Happens when the activity is fully visible and ready for the user to interact.
4. onPause(): Happens when the activity goes into the background, but it’s still visible.
5. onStop(): Happens when the activity is no longer visible to the user.
6. onRestart(): Happens when the activity is brought back from the background to the
foreground.
7. onDestroy(): Happens when the activity is about to close and is no longer needed.
Fragment Lifecycle: A fragment is a part of an activity’s screen. It has a similar lifecycle to
activities but with some extra methods.
1. onAttach(): Happens when the fragment is attached to an activity.
2. onCreate(): Happens when the fragment starts.
3. onCreateView(): Happens when the layout of the fragment is created.
4. onStart(): Happens when the fragment becomes visible.
5. onResume(): Happens when the fragment is ready for interaction.
6. onPause(): Happens when the fragment goes into the background.
7. onStop(): Happens when the fragment is no longer visible.
8. onDestroyView(): Happens when the fragment's view is being destroyed.
9. onDetach(): Happens when the fragment is detached from the activity.
Android App Architecture
Android App Architecture refers to how you organize the parts of your app, so it’s easy to
manage and update.
MVC (Model-View-Controller): A pattern where:
o Model: Handles the data and business logic.
o View: Shows the user interface.
o Controller: Connects the model and the view.
o Example: Older Android apps used this pattern where activities were used as
controllers.
MVVM (Model-View-ViewModel): A pattern where:
o Model: Handles the data.
o View: Shows the UI.
o ViewModel: Holds the data for the UI and handles business logic.
o Example: Modern Android apps use MVVM, like Google’s Jetpack components, to
manage UI updates.
MVP (Model-View-Presenter): A pattern where:
o Model: Handles the data.
o View: Shows the UI.
o Presenter: Handles all the UI logic and communicates with the model.
o Example: A weather app that gets weather data and shows it to the user.
Components of Android Architecture:
Activities and Fragments: Handle UI and user interaction.
Services: Handle background tasks.
Broadcast Receivers: Listen for system events like incoming calls or Wi-Fi changes.
Content Providers: Handle data shared between apps.
LiveData: It’s a data holder that updates the UI automatically when data changes. It’s lifecycle-aware,
meaning it only updates the UI when it’s visible (so no updates happen when the app is in the
background).
LiveData Observers: These are the parts of the app that listen for changes in LiveData and update the UI
accordingly when the data changes.
Room Database
Room: A library that simplifies using databases in Android. It makes working with databases easier by
providing a layer on top of SQLite (a database system).
o Entities: Represent tables in the database.
o DAO (Data Access Object): Defines methods to interact with the database (like fetching or saving
data).
o Database: The main entry point to access the database.
Advanced RecyclerView Use Cases
RecyclerView: A flexible view used to display lists of data efficiently. It recycles views to save
memory.
o Multiple View Types: RecyclerView can display different types of items, like text and
images, in the same list.
o Item Animation: You can add animations to RecyclerView items when they are added or
removed.
o Swipe-to-Dismiss: You can allow users to swipe an item to delete or perform an action.
o Endless Scrolling: When the user scrolls to the bottom, more data is automatically
loaded.
o Drag-and-Drop: You can let users reorder items in the list by dragging them.
o View Holder Pattern: Recycles views to save memory by using a ViewHolder.
o Nested RecyclerViews: RecyclerView can be used inside another RecyclerView to create
more complex layouts.
Coroutines and Room
Coroutines: A feature in Kotlin that helps you run tasks that take time (like downloading data)
without blocking the app’s main thread (which could freeze the app). Coroutines make handling
such tasks easier and faster.
Room with Coroutines: You can use coroutines to perform database operations without
freezing the app. This keeps the UI responsive even when the app is working with a database.