Android14_Kotlin
Android14_Kotlin
1. Introduction to Android
1.1. IntroductiontoMobileApplicationDevelopment
Mobile OS are keep on introducing from Palm OS in 1996 to Windows pocket PC in
2000 then to Blackberry OS and Android. One of the most popular used mobile OS
now days are ANDROID. There are around 2.0 lack+ games, application and
widgets available on the market for Android users. Android is a powerful Operating
System supporting a large number of applications in Smart Phones. These
applications make life more comfortable and advanced for the users. Android is a
Linux-based operating system designed for mobile devices such as smartphones
and tablet computers. The Android is a light weight OS and can easily embedded
into different hardware devices like networking equipment, smart TV systems
including set top boxes and built in systems and various devices like as house hold
appliances and wrist watches.
1.2.What is Android
It is a platform that provides tools and technologies which can used to develop and
build mobile.
Applications. The Android platform is open and free software stack that includes an
operating system, middleware services and also key applications for use on mobile
devices.The Android environment uses the Linux operating system at its core.
Middleware Services makes it easier for software developers to perform
communication and input/output, so that developers can concentrate on the specific
purpose of their application without need of concentrating on input output resource
coding of device. Android provides a middleware layer including libraries that provide
services such as data storage, screen display, multimedia, and web browsing.
Because the middleware libraries are compiled to machine language, services
execute quickly.
Android also provides an application framework that developers integrate into their
applications for application development.
1.4. Features
1) Open source framework, Android OS is open source and it is part of the Open
Handset Alliance, most of the leading handset manufacturers in the world have
Android phones.
2) Uses of tools are very simple.
3) Availability of Apps, majority of the apps in Google Play are free as compared to
the paid apps on iPhone. 4) Inbuilt support for the Flash.
5) Social networking integration like with Twitter, Facebook, ..etc
6)Integrated Applications & Features, Eg: Android allows an option to share, after
taking a photo with the Camera.
7) Free to customizes, we can customize widgets as our wish with new properties.
8) Better Notification System (comprises emails, updates from various widgets.)
9) Updated user interface design
10) It has a better App Market, to easily upload and download.
11) Different Resolutions for Different Screen Sizes.
12) System wide copy and paste functionalities.
13) Multi touch interfacing
14) Java Support so can develop Robust applications.
15) Multi language support
16) Multitask Support, i.e Android phone can run different applications
simultaneously, which obviously makes it easier to multitask and improves the
overall functionality of the phone.
Leve S 2021
l 31
Androi
d 12
Leve O 95.1%
l 26
Androi
d 8.0
Leve N 97.0%
l 24
Androi
d 7.0
Leve HONEYCOMB_MR1
l 12
Androi
d 3.1
Leve HONEYCOMB
l 11
Androi
d 3.0
Leve ECLAIR
l5
Androi
d 2.0
Éclair
This version released on October 26, 2009.
Features
Gingerbread
This version is released on December 6, 2010.
Features:
IceCreamSandwich
This version released on November 14, 2011.
Features
JellyBean
This version released on June 27, 2012.
Kitkat:
This version released on Sep 30, 2013.
Features
Lollipop
This version released on Oct 15, 2014.
Features
Nougat
This version released on June 30, 2016.
Features
From android 7.0 onwords battery life is improved, when mobile is ideal
battery is aslo used in very very rare percentage.
• Data Saver
From this version onwards device wont consume more data for
background process. So our data could be safe.
• App Shortcuts :
It should displays the explore of all files into based on format like size,
space etc.
This is the good news for who are single music with single jack it can
support without disturbance.
• Emergency Info :
Even if phone is in locked also here can work emergency features like
Road block on GPS, battery low etc.
This are the key board shortcuts for tab users who are using physical
keyboards..
Based on the mobile location automatically wifi turn and turn off facility
introduced, so automatically battery life is saved.
7. More Granular Storage Controls
By selecting the file it self we can find the how much space that file is
occupying and also OS is also occupying less memory compare to
previous versions.
8. Picture-in-Picture Mode
picture in picture mode is nothing but while am watching one videos if
am searching other video then older video should come to right of
bottom the with playing only so without disturbance we can check other.
9. Autofill Framework
Some our regularly activities like entring address and credit/devbit card
information those fileds automatically fills based on the previous data so
that here we can save the time .
10. Rescue Party
When a fatal bug comes through and your device starts crashing, the os
will trying to automatically fix the issue,that is Rescue Party, basically
it fixes when your phone repeatedly reboots, or when a app
continuously crashes.
11. Notification Channels
Normally when we no .of notifications latest one should top but here we
can gave priority so that always that notification on the top.
12. Adaptive Icons
Up to now in android we have only styles of icon like Square,circle,oval
are available but from this version on words we can customize icons.
13. Hi-Fi Bluetooth Codecs
Bluetooth has always lower audio quality when compared to a set of
wired headphones. So from this version google implroved Bluetooth
range with high frequency.
14 Tab Navigation
Up to only we have option to acces single tab in browsers but from 8.0
onwards we can manage multiple tabs in browsers like
Laptops/Desktops.
15. App Drawer Improvements
This is easy navigation to installed app once we enable this feature if
you touch any where on the screen it should open navigation from left
side with all apps as listview, so easily we can access those.
16. Wider Color Gamut in Apps
Upto 7.0 when we want to use any colors of Image, backbround & text
color only we have option RGB but from 8.0 onwards Render wide color
gamut content with using below code (extra palet option to select color).
android:colorMode=“wideColorGamut”
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
14 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
BEST 13 FEATURES OF
ANDROID 9.0 PIE
Gesture Navigation
In Previous versions Android has used a standard three-button
navigation bar at the bottom of the screen for ages. In Pie, you can drop
the standard Back, Home, and Recent buttons in favor of a new gesture-
based navigation system.
If want to try this feature, click on Settings > System > Gestures >
Swipe up on Home button. Your navigation bar will change right away.
Adaptive Battery and Brightness
Adaptive Battery is an expansion of the Doze feature introduced in
Android 6 Marshmallow. Doze put apps that you weren’t using into a
“deep sleep” to prevent them from wasting battery. Now, Adaptive
Battery goes further by learning about the apps and services you use
most often, then adjusting what you don’t use as much to use less
battery.
App Actions
Google’s launcher already recognizes the apps you’re most likely to use
based on the time of day. Now, App Actions let you quickly start tasks by
predicting what you want to do.
For example, you might see a shortcut to start Google Maps navigation
to work in the morning. At work, you might see an App Action to chat
with your coworker on Hangouts. And when you plug in headphones,
you’ll see an App Action for your most recent playlist.
Slices
Similar to App Actions, Slices let you jump right to certain actions in
apps. For instance, Google says that if you search for uber on your
phone, you’ll see a shortcut to hail a ride to work, complete with price
and ETA.
Improved Security Features
The first is that this version of Android “restricts access to mic, camera,
and all SensorManager sensors from apps that are idle” according to
Google.
Second, a new lockdown mode fortifies your phone in emergency
situations. After enabling this at Settings > Security & location > Lock
screen preferences > Show lockdown option, you can tap Lockdown on
the Power menu. This instantly locks your phone, disables fingerprint
unlocking and Smart Lock, and hides notifications on your lock screen
Digital Wellbeing
The dashboard shows you how many notifications apps send you, how
much time you spend in apps, and how often you check your phone. You
can also set daily time limits to keep yourself from wasting hours in time-
sinking apps
New Accessibility Menu
A new menu in Android Pie makes it simple to access common functions
for users who need assistance.
Enable this menu at Settings > Accessibility > Accessibility Menu. Turn
on the Use service slider and confirm the prompt, and you’ll see a new
icon to the right of the navigation bar. Tap this anytime to bring up a
large menu with shortcuts to Volume, Recent apps, Quick Settings, and
more.
New Screenshot Shortcut
The default Power + Volume Down button combination for screenshots
is a little awkward. Thus, in Android Pie, you can take a shortcut from the
Power menu anytime.
What’s more, you can also tap the Edit command in the notification that
appears to make adjustments to your shot right away.
Easier Screen Rotation
Android automatically switches your screen orientation based on how it’s
situated. You can lock the orientation to portrait or landscape, but this
turns into a pain if you need to switch often.
In Pie, if you have Auto-Rotate turned off, you’ll see a new icon on the
right side of the navigation bar when you rotate your device to
landscape. Tap it to lock in landscape orientation, and it will stay even if
you turn back to portrait. Just tap the icon again to rotate back to portrait.
Volume and Sound Improvements
When you press a Volume button, you’ll notice the slider now appears
on the right side instead of the top. What’s more, pressing volume
buttons now changes the Media volume instead of the Ringer volume
like before. This simple volume tweak makes it easier to avoid opening a
YouTube video and accidentally playing it at full blast.
Tap the Note icon to mute or unmute media audio. You can tap the icon
above this to toggle your Calls volume between Ring, Vibrate, and Mute.
You’ll need to select the Gear icon to open the Sound menu and make
detailed adjustments.
Selectable Dark Mode
Android Oreo included a dark mode, but the system automatically
decided whether to enable it based on your wallpaper. Now you can
choose for yourself at Settings > System > Display > Advanced > Device
theme
Easier Text Selection
If you copy and paste a lot, you’ll love a small change in Pie. Now when
you long-press to select text and grab the handles, a little magnifier lets
you see exactly what you’re selecting.
More Notification Information
If you want to see which apps are sending distracting notifications, head
to Settings > Apps & notifications > Notifications. In the Recently sent
section, you can see which apps have pinged you recently. Tap See all
from last 7 days to view more info.
Changing Most recent to Most frequent lets you find the worst offenders.
Android will also suggest that you disable notifications from apps you
swipe away frequently. Don’t forget about the notification channels
introduced in Oreo, either.
ANDROID 10 FEATURES
A dark mode
Dark mode can be activated by a quick setting or when you activate the
battery saver option. Android 10 features, having been requested for a
long time now. But the Mountain View company is also working with
third-party developers to implement dark modes in their apps.
Smart Reply for all messaging apps
Smart Reply is one of the better Google features out there, predicting
what you’re going to say in response to a message. It’s currently
available for Google apps, but it’s now coming to all messaging apps in
Android 10.
This means you can now get suggested responses in the likes of
WhatsApp and Facebook Messenger — a handy way to save time when
a short response will do. These suggestions are all made using on-
device machine learning, purportedly maintaining your privacy as the
relevant information isn’t sent to Google’s servers.
A better sharing menu
According to Engadget, the feature uses the new Audio Streaming for
Hearing Aids protocol (ASHA) to stream music, calls, and other audio
from a Pixel phone.
The feature is reportedly compatible with the Pixel 3 and Pixel 3a series
for now, but Google is open-sourcing the platform. So hopefully we
quickly see more phones and hearing aids offering this truly useful
function.
Security updates via Play Store
Another major initiative coming to Android 10 is Project Mainline, an
effort by Google to deliver some security updates via the Play Store.
This significantly reduces the waiting time for security updates in theory,
as you don’t have to wait for your operator to approve the update.
Furthermore, it shouldn’t require a lengthy installation process, working
in a similar manner to app updates.
The only real downside to this solution is that some security
vulnerabilities can’t be patched in this fashion, necessitating a traditional
security update anyway. But it’s definitely a major step in the right
direction.
Qualcomm has also announced that phones equipped with its 2020
chipsets will let you update graphics drivers via the Play Store. It’s
believed that this is due to Project Mainline as well. This is definitely one
of the coolest Android 10 features if you have a supported phone.
Wet, overheating USB warnings
Android 10’s release has also seen XDA uncover evidence of new USB-
related functionality in the update. More specifically, the operating
system will now display a warning when your USB port is wet. Any
connected accessories will also be disabled until you either manually
enable them or until the phone detects that the port is no longer wet.
Furthermore, the latest Android update will also issue a warning if your
USB port is overheating. You’ll still need to unplug your phone from the
charger or USB cable of course, but the warning is welcomed
nonetheless.
ANDROID 11 FEATURES
Built-in screen recording
Android 11 brings a feature some custom Android forks already have –
built-in screen recording. This lets you use easily-accessible controls
within the phone to create a video of what’s on your screen, similar to
screenshots.
You can even record the sound of your phone, or use the mic to narrate
what you’re doing, so this should be a great feature for creating short-
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
21 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
form video like TikToks, or for making tutorial videos to help less tech-
savvy relatives make the most of their smartphone.
Related to this, the Android 11 sharing functions have seen wider rollout
to apps, so you can easily copy and paste images, text and videos from
one app and send them straight to another.
New conversations tab
When you swipe down from the top in Android 10, you bring down your
notification bar – well, in android 11, that’s split into two sections,
consisting of your notifications, and your ‘conversations’.
These conversations are basically just chat notifications from chat apps
like WhatsApp, Facebook Messenger and Twitter, so you know they’re
probably more worth paying attention to than the other notifications.
This way you can easily see if people need you, and reply straight away
too. You can also now pin conversations to ‘Bubbles’ – you might have
seen these for Facebook Messenger, where a floating icon appears
above other apps to show you that you have a message.
Now you can get messages from more apps to appear as bubbles, and
you can pin them there too so the chat is always easily-accessible.
A related improvement is that Gboard, the default Android keyboard, will
now auto-fill forms with relevant information, similar to what Chrome
currently does, which should save time if you’re frequently filling out your
information.
Smart home and media controls
The new Android 11 update brings loads of changes for people who use
loads of smart home devices.
From one easily-accessible menu (accessed by long-pressing the power
button) you can control all the IoT (Internet of Things) devices you have
connected to your phone, as well as NFC bank cards.
Talking of home, there’s a new Bedtime Mode in the phone which you
can set to run during the night, which turns on Do Not Disturb and makes
the phone screen black-and-white to protect your vision.
There are new media controls too. It’s now easier to make music play
from other devices connected to your phone, like Bluetooth speakers or
other gadgets.
Plus, Android Auto now works wirelessly on your car, saving you from
having to fiddle with wires to get it working. And on the topic of transport,
now when you turn on Airplane mode, any headphones connected via
Bluetooth will stay connected, so you won’t have to reconnect them.
Improved accessibility
Google has improved its Voice Access mode in Android 11, although
there isn’t too much information on what’s changed.
ANDROID 12 FEATURES
Wallpaper-based Dynamic Theming
The ‘monet’ dynamic theming engine is one of the highlights of Android
12 and what makes Material You so special. The engine will pull the
colors from the wallpaper applied and use them throughout the UI and
system accents for theming purposes. What makes the experience even
better is that the colors are also applied to apps that have been updated
to support the theming engine.
The dynamic theming engine in Android 12 will make sure you never get
bored of the UI. A simple wallpaper change will be enough to give
everything a fresh coat of paint.
Game Dashboard
A Pixel-exclusive Android 12 feature for now, Game Dashboard aims to
improve your gaming experience by overlaying some important tools and
information, like the ability to record your gameplay, streaming your
gaming session on YouTube, or displaying a live FPS counter so that
you can get an idea of how your phone is performing.
You can also select from one of the three different gaming profiles —
Performance, Standard, and Battery Saver — depending on your
requirements. However, this particular feature will only work with games
that have been updated to take advantage of the new APIs in Android 12
One-handed mode
Taking a cue from third-party Android skins, Google has added a native
one-handed mode in Android 12. As the name indicates, the feature
makes it easy to use your phone with one hand — a boon for devices
with large displays and gargantuan size like the Pixel 6 Pro.
On your device, head over to Settings > System> Gestures. Tap on
One-Handed mode and enable the toggle. Now, you can enable one-
handed mode by simply swiping down from the bottom edge of the
display. Do note that this feature only works when you are using gesture
navigation on your device.
Quick Tap
Taking a cue from the Back Tap gesture in iOS 14, Google has
introduced a new Quick Tap feature in Android 12. With a simple double-
tap on the back of your phone, you can launch an app of your choice,
control media playback, take a screenshot, show recent apps, and
trigger Google Assistant.
The Quick Tap gesture is tucked under Settings > System > Gestures in
Android 12. Now, depending on your preference, select an action that
you want to assign to Quick Tap.
Direct share in the Recents overview menu
The quick image sharing feature from the Recents overview menu has
been further improved in Android 12. Now when you simply drag-and-
drop images from Instagram, a web page in Chrome, or other similar
apps, a list of your recommended contacts will show up at the bottom for
quick and easy sharing. This makes the entire process of sharing
content from the Recents overview more streamlined and convenient.
Privacy Dashboard
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
25 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
Scrolling screenshots
This is a feature that Google has taken ages to bring to its flavor of
Android. Gone are the days when just taking a screenshot would suffice
— users now frequently need to screenshot long lists. With scrolling
screenshots, you’ll no longer have to take multiple screenshots to
capture a long list. Instead, take a screenshot and from the toolbar tip
that pops up at the bottom, tap Capture more. Remember that this option
will only show up in lists or where it is actually possible to take a long
screenshot.
ANDROID 13 FEATURES
Android 13 Released on January 2022, Android 13 has not been
released yet.
However, Android versions typically come with various improvements,
new features, and enhancements to performance and security. Some
common areas of improvement in Android updates include:
ANDROID 14 FEATURES
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
27 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
In general, laptop webcams aren’t very clear — they usually offer just
okay quality, like 720p or even less. We’ve all faced this problem. There
may be a cool solution in Android 14 for those looking for a better
webcam. With this solution, you can use your Android phone as a 1080p
camera for your computer.
Consider this scenario: you plug your phone into your computer, and a
menu appears. In that menu, you could choose “webcam,” and your
phone’s camera would become your computer’s camera. Currently, this
feature isn’t part of the system, not even hidden away in a secret setting.
If Google gives it the green light, it might appear in Android 14. You
might be able to get a fancier camera setup down the road without
spending more money.
Enhance lock screen
With Android 14, you can customize your phone in a variety of ways.
One big thing how your lock screen appears. Your clock can look
different and even what apps appear at the bottom corners can be
customized.
If all goes well for Google, these changes will be included in the official
Android 14 release next month. Just a heads-up, the clock styles they
showed at I/O weren’t great. We hope the final versions will be more fun
and less boring.
Satellite connectivity
Your phone might soon be able to connect to satellites with Android 14!
As a result, you can send important messages even without cellular or
WiFi service. Apple did this with their iPhone 14 series last year.
According to a tweet from TeamPixel, Android 14 will support satellite
connections for sending messages. Additionally, Google Pixel and
Samsung Galaxy phone owners may be the first to test it. For this
satellite thing to work, your phone needs special hardware. It depends
on other Android phone makers whether they add this later.
Imagine yourself in a place where there is no cell signal or WiFi. Texts
can still be sent if your phone supports satellite technology. There’s
something magical about it when you’re out in the wilderness!
Charging Pill
With the latest update for Android 14 Beta, a new feature is added. A
pretty animated pill will appear on your screen when you connect your
device to charge. This discovery was made by Mishaal, and
interestingly, the Android Beta Twitter account accidentally spilled the
beans on it.
Tapping the pill has no special function, but it’s a visually appealing
addition to Material You.
When you charge your device, it’s like a little bit of fun, adding a touch of
excitement.
Drag drop feature(Gesture support enhance)
There was a cool trick in iOS 15 that let you move text and pictures
around. Guess what? The Android 14 operating system will be able to do
the same thing. Actually, it’s already there if you’re using the Android 14
Beta 3 version, and it works really well.
Here’s the deal: pick some text, hold it down, and move it. Then, use
your other hand to switch to another app where you want to put the text,
and let go. There it is, the text appears like magic. As soon as Android
14 is released, you’ll be able to do the same thing with pictures as well
Cool, right?
Flash notifications
I really like the Notification Flashes feature. That’s great for people who
frequently check their phones in noisy places where hearing notifications
is difficult, or for those with hearing challenges.
To get it working, just head to your phone’s Settings, then go to Display,
and find Flash notifications. From there, you can flip the switch for
Camera Flash and/or Screen Flash.
There’s an extra cool thing you can do with Screen Flashes. You don’t
have to stick with one color. Nope, you can choose from a variety of
colors. Moreover, you can see how each color will look before making a
decision. Check out how the color flashes, then decide if it’s right for you.
Trying on different outfits before you pick the right one is like trying on
clothes before you buy them!
Device Manufacturing Date
In Android 14, by this feature allows you to easily find out the year your
phone was produced. All you need to do is navigate to Settings > About
Phone > Model. Once you’re there, you’ll spot the Manufactured year
displayed alongside details like Hardware version, Serial number, and
model.
Now, you might not think this information is super crucial, but it can be
surprisingly handy, especially when you’re considering purchasing a pre-
owned or refurbished device that doesn’t come with its original retail
packaging. Knowing the year of manufacture can give you a better idea
of the phone’s age and possibly its condition.
So, while it may not be something you use every day, it’s a small yet
useful addition for those times when you’re exploring options for buying
a second-hand device.
Extreme Battery Saver option
In Android 14, there’s this really cool thing called “Fast Pair.” It’s like a
special button hidden in the Connection settings. What’s it do? Well, it
makes connecting your Bluetooth stuff (like headphones or speakers) to
your Android phone super easy. No more dealing with tricky steps to
make them talk to each other.
With Fast Pair, you just tap a bit, and boom! Your Bluetooth stuff is
friends with your Android. Imagine it like a magical shortcut for making
gadgets work together.
So, when you want to use your cool wireless stuff, you don’t need to be
a tech wizard. It’s all about making things faster and simpler, so you can
enjoy your devices without the hassle. That’s Android 14 being awesome
for you!
Grant partial access to photos and videos
basically, this feature allows you to set additional filters for specific apps
that request gallery access. Many social networking apps currently ask
for permission to access our galleries, giving them the ability to retrieve
all our mobile device images.
In Android 14, you can establish extra filters between these apps. For
instance, let’s say I’ve organized multiple albums or folders within my
gallery, each containing different types of images, such as social life
photos and personal documents. Prior to Android 14, there was no
option to exclusively share only my social life images with these apps.
However, in Android 14, I can now apply this filter specifically for these
applications. This way, I can safeguard my other images from being
accessed by these apps. It’s a welcomed privacy enhancement that
grants users more control over their image sharing.
Background Install Control (bloatware remover)
By this option you able to know and delete bloatware they can run on a
background without your knowledge. basically by this feature you can
track apps that are installed in the background. Any apps that are silently
downloaded in the background are listed in this menu.
You can then look through the menu to delete apps you don’t want.it
would be a lot easier to find and get rid of any bloatware weighing down
your device.
Regional preference on calendar and number
Using this option, you can run an app according to your language
preference. Globally, many users want to use specific apps in their
preferred language without changing the system’s language.
In Android 14, you have more application options, so you can set
different apps to different languages according to your preference.
Android 13 already supported this to some extent, but in Android 14, you
have more application options to select from.
Enhances Health paring apps
With Health Connect, you can get all the important health and fitness
information from different apps in one convenient location. It’s like a
central organizer for your health information. If you have a Samsung
health app, a Fitbit app, or a Peloton fitness device, the Health Connect
app can pull data from all of them.
Your app store currently offers the Health Connect app for download.
This allows you to easily access and manage your health data from
different sources. However, there’s exciting news! Google has just
announced that starting with the release of Android 14 beta 2, Health
Connect will be included as a built-in feature of the Android operating
system.
This means that when you get a new device or update your existing
Android device to Android 14 or later, you’ll automatically have the
Health Connect app pre-installed. You won’t need it.
Furthermore, the built-in integration of Health Connect means that you’ll
also receive updates seamlessly. These updates will happen
automatically as part of the regular Android system updates, ensuring
that you always have the latest features and improvements for managing
your health data without any extra effort on your part.
This streamlined experience makes it easier for users to stay on top of
their health and fitness information, all while enjoying the benefits of a
hassle-free setup and continuous updates.
I believe these 14 features are unique and good, so please let me know
if you have any others apart from these 14 features. I’ve gathered
information from a number of websites and researched. Please leave a
comment if you notice anything that does not seem right or if you have
any thoughts to share. It’s really important for me to hear your thoughts!
ARCHITECTURE
Architectute is nothing but physical structural plan or block diagram of
some view.
Android is Linux based software stack , it is open source for lot of
devices. For developers they are giving full acces to Frame work API
acces to develop core level applications, because of that only
manufactrers are customizing their own features.
The following diagram is shows rhe components of android.
SYSTEM APPS
The top most layer is system APPS. Normally normal devices will come
with Contacts, Messages, Browsers, calenders etc.. so here user can
install any number of applications which they are using, some third party
applications may be we can set as default apps like browers,
Messengars and keyboards
These all very helpful to for because if developer is developing his own
applications he can those functionalities for example if we developemnet
any application related to SMS just developer invoke the services then
next portion of the service like sending sms & sms status will be done
android system only
JAVA API FRAMEWORK
The Android OS complete feature set is avaible for devlopers in the form
of APIs those APIs are written by Java language. This are very helpful
to developers to simplify their app development, even developer can use
cor part of architecture alos to build apps like components and services
which are included in API framework. The following are few of the APIs
• View System:
• Content Providers:
Content providers is nothing but we can access the data from other
applications like while sending the message we are accessing contacts
data & in now days all social media applicatiosn we are accessing the
contacts, gallery etc.
Managers:
These are also API but non coding portion providing layouts, images,
strings, colors, default styles etc.
• Resource
Resource manager provides acces to resources for our developemnet
such as Strings, Images, nimations, graphics, colors, vidoes etc.
• Notification
Notification Manger will help enable the custom notification in status bar.
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
42 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
• Activity
• Location
This Api could help to acces the geo location,navigation using Services
of Android Architecture.
• Package
Each package contains multiple java classes and it can control all the
functionalities of those classes.
• Telephony
It can communicate with networks like mobile data, wifi, hotspot &
sharing data etc.
• Window
It can handle the multiple windows in our device. For example
symultantously while listing the songs chatting with some one so its
handling two two different windows at a time like same some windows
cache memory & browser windows etc.
Many of the android componnts and servicew are build from native code
those android runtime & Hardware abstraction layers because native
libraries wriiten in C & C++.
• Webkit
It can support all type of browsers.
• Open Max AL
• Libc
• Meida framework
Android apps can support all type of media like jpg, png, mp3, mp4 etc.
• Open GLES
From android 5.0 and above version of android with its own process and
its own instance of Android Runtime. ART is designed for low memory
device by excuting the DEX (byte code) files to run on virtual
devices,and bytecode is designed special optimized for low memory
devices.
ART features
Note:
Previosly Lower version (less than 5.0) is run in Dalvik virtual machine,
now as well as it can run in ART also, then it can run DVM as well, but
vicevera is not possible.
• Core Librariries
Android application also includes a set of core libraries that provide most
of the runtime functionality of the Java programming language, and it
includes android 8.0 features as well
API Android system loads the library module for that hardware
component.
1. Linux Kernel
Linux kernel is hardware layer. For example, the ART relies on the Linux
kernel for functionalities such as threading and low-level memory
management. Linux kernel allows Android to take advantage of key
features like develop hardware drivers for a well-known kernel such as
Audio, Keypad, Shraed memory, Usb, Bluetooth, Binder(IPC)Display,
Camera, Wifi, Power Management etc.
INSTALLATION OF ANDROID
STUDIO
For Android development with Kotlin you need download Android Studio
develop apps. You can use Android Studio to test your apps with a large
can also build production apps and publish apps on the Google Play
store.
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
45 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
The installation is similar for all platforms. Any differences are noted
below.
might take some time depending on your internet speed and the
complexity of your project.
• Project Structure: Once the Gradle build is complete, you'll see
your project structure in the left sidebar. This includes folders like
"app," "res," and "Gradle Scripts." The "app" folder contains your
app's code and resources.
• Run Your App: Before you start coding, it's a good idea to run your
app to make sure everything is set up correctly. You can do this by
clicking the green play button in the toolbar or by going to Run > Run
'app'.
• Choose a Device: Android Studio will prompt you to select a
device to run your app on. You can choose a physical device
connected to your computer or an emulator. If you don't have any
devices set up, you can create a new virtual device by clicking
"Create New Virtual Device."
• Wait for Build: Android Studio will build your project and deploy it
to the selected device or emulator. This process might take some
time, especially the first time you run your app.
• View Your App: Once the build is complete, you should see your
app running on the selected device or emulator. Congratulations,
you've successfully created and run your first Android Studio
project!
• app:
• manifests: Contains the AndroidManifest.xml file, which
describes essential information about your app to the
Android system, such as activities, permissions, and
services.
• java: Contains the Java (or Kotlin) source code for your app.
This is where you write your activities, fragments, services,
and other components.
• res: Contains all the resources used by your app, such as
layouts, drawables, strings, and values.
• drawable: Contains images and other drawable
resources.
OVERVIEW OF XML
XML stands for Extensible Mark-up Language.XML is a very popular
format and commonly used for sharing data on the internet. This chapter
explains how to parse the XML file and extract necessary information
from it.
HTML is a forgiving language. It tolerates a host of sins, from imprecise
markup to altogether missing elements, and can still generate a web
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
48 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
Here are some examples: XHTML, WSDL for describing available web
services, WAP and WML as markup languages for handheld devices,
RSS languages for news feeds, RDF and OWL for describing resources
and ontology, SMIL for describing multimedia for the web
RULES
There are nine basic rules for building good XML:
Right:
<author>Ernest Hemingway</author>
<p>Roses are Red</p>
<hr></>
<hr />
Rule 3: All Tags Must Be Properly Nested
When you insert (nest) one tag within another, pay attention to the order
in which you open each tag, and then close the tags in the reverse order.
If you open element A and then element B, you must first close B before
closing A. Even HTML tags that usually will work without a strict
structure must follow the stricter XML rules when they’re used within an
XML file.
Wrong:
<A><B>Text</A></B>
<b><i>Text</b></i>
Right:
<A><B>Text</B></A>
<b><i>Text</i></b>
Rule 4: Tag Names Have Strict Limits
Tag names can’t start with the letters xml, a number, or punctuation,
except for the underscore character (_).
The letters XML are used in various commands and can’t start your tag
name. Numbers and punctuation also aren’t allowed in the beginning of
the tag name.
Wrong:
<01_author>
<“author”>
Right:
<author>
<_author>
Rule 5: Tag Names Are Case Sensitive
Uppercase and lowercase matter in XML. Opening and closing tags
must match exactly. For example, <ROOT>, <Root>, and <root> are
three different tags.
Wrong:
<author>Hemingway</AUTHOR>
<Author>Hemingway</aUTHOR>
Right:
<author>Hemingway</author>
<AUTHOR>Hemingway</AUTHOR>
Rule 6: Tag Names Cannot Contain Spaces
Spaces in tag names can cause all sorts of problems with data-intensive
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
51 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
LAYOUTS
A layout defines the visual structure for a user interface, such as the UI
for an activity or app widget. You can declare a layout in two ways:
1. Declare UI elements in XML. Android provides a straightforward XML
vocabulary that corresponds to the View classes and subclasses, such
as those for widgets and layouts.
2. Instantiate layout elements at runtime. Your application can create
View and ViewGroup objects (and manipulate their properties)
programmatically.
The Android framework gives you the flexibility to use either or both of
these methods for declaring and managing your application’s UI. For
example, you could declare your application’s default layouts in XML,
including the screen elements that will appear in them and their
properties. You could then add code in your application that would
modify the state of the screen objects, including those declared in XML,
at run time.
In Android we have different types of Layouts are there. Will discuss
each layout in detail
RELATIVE LAYOUT
In Android, RelativeLayout let you position your component base on the
In RelativeLayout, you can use “above, below, left and right” to arrange
Note: The RelativeLayout is very flexible, but hard to master it. Suggest
you use Studio IDE to drag the component, then view study the Studio
on both the X and Y axes. Possible values are top, bottom, left, right,
by gravity.
“@[+][package:]type:name”
the bottom edge of the given anchor view ID and must be a reference to
android:layout_alignLeft: Makes the left edge of this view match the left
view match the bottom edge of the parent. Must be a boolean value,
match the end edge of the parent. Must be a boolean value, either “true”
or “false”.
match the left edge of the parent. Must be a boolean value, either “true”
or “false”.
view match the right edge of the parent. Must be a boolean value, either
“true” or “false”.
match the start edge of the parent. Must be a boolean value, either “true”
or “false”.
match the top edge of the parent. Must be a boolean value, either “true”
or “false”.
android:layout_alignTop: Makes the top edge of this view match the top
android:layout_below: The top edge of this view below the given anchor
“@[+][package:]type:name”.
“false”.
LINEAR LAYOUT
android:id: This is the ID which uniquely identifies the layout.
android:baselineAligned: This must be a boolean value, either “true” or
“false” and prevents the layout from aligning its children’s baselines.
android:baselineAlignedChildIndex : When a linear layout is part of
another layout that is baseline aligned, it can specify which of its children
to baseline align
android:divider : This is drawable to use as a vertical divider between
buttons. You use a color value, in the form of “#rgb”, “#argb”, “#rrggbb”,
or “#aarrggbb”.
android:gravity : This specifies how an object should position its content,
on both the X and Y axes. Possible values are top, bottom, left, right,
center, center_vertical, center_horizontal etc.
android:orientation: This specifies the direction of arrangement and you
will use “horizontal” for a row, “vertical” for a column. The default is
horizontal.
android:weightSum: Sum up of child weight
Example Code with weight Property
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
59 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#0707f1"
android:weightSum="10">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:background="#f9f003"
android:orientation="horizontal">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_marginRight="20dp"
android:layout_weight="1"/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1"/>
<Button
android:id="@+id/button21"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:background="#94f50b"
android:orientation="horizontal">
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1"/>
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
60 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="#33111b"
android:orientation="horizontal">
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_gravity="center"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
TABLE LAYOUT
TableLayout positions its children into rows and columns. TableLayout
containers do not display border lines for their rows, columns, or cells.
The table will have as many columns as the row with the most cells. A
table can leave cells empty. Cells can span multiple columns, as they
can in HTML. You can span columns by using the span field in the
TableRow.LayoutParams class.
Note: Cells cannot span multiple rows.
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
61 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:padding="10dp"
android:background="@drawable/border"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="aabbbbgchgcchh"
android:padding="10dp"
android:background="@drawable/border"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8888"
android:padding="10dp"
android:background="@drawable/border"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[email protected]"
android:padding="10dp"
android:background="@drawable/border"/>
</TableRow>
</TableLayout>
</LinearLayout>
For Table layout if you want borders need to implement below code and
apply as a background for each widget
In drawabale folder create one xml with some name with below code
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:color="#000"
android:width="1dp"></stroke>
</shape>
FRAME LAYOUT
FrameLayout is designed to block out an area on the screen to display a
single item. Generally, FrameLayout should be used to hold a single
child view, because it can be difficult to organize child views in a way
that’s scalable to different screen sizes without the children overlapping
each other. You can, however, add multiple children to a FrameLayout
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
64 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
CONSTRAINT LAYOUT
The ConstraintLayout is a powerful new class, imagine a RelativeLayout
on steroids – yea, that’s the ConstraintLayout. It allows us to lay out child
views using ‘constraints’ to define position based relationships between
different views found in our layout. The aim of the ConstraintLayout is to
help reduce the number of nested views, which will improve the
performance of our layout files. The layout class also makes it easier for
us to define layouts than when using a RelativeLayout as we can now
anchor any side of a view with any side of another, rather than having to
place a whole view to any side of another
<?xml version="1.0" encoding="utf-8"?>
ARCHITECTURE OF ANDROID
Architectute is nothing but physical structural plan or block diagram of
some view.
Android is Linux based software stack , it is open source for lot of
devices. For developers they are giving full acces to Frame work API
acces to develop core level applications, because of that only
manufactrers are customizing their own features.
The following diagram is shows rhe components of android.
cor part of architecture alos to build apps like components and services
which are included in API framework. The following are few of the APIs
• View System:
• Content Providers:
Content providers is nothing but we can access the data from other
applications like while sending the message we are accessing contacts
data & in now days all social media applicatiosn we are accessing the
contacts, gallery etc.
Managers:
These are also API but non coding portion providing layouts, images,
strings, colors, default styles etc.
• Resource
• Notification
Notification Manger will help enable the custom notification in status bar.
• Activity
• Location
This Api could help to acces the geo location,navigation using Services
of Android Architecture.
• Package
Each package contains multiple java classes and it can control all the
functionalities of those classes.
• Telephony
It can communicate with networks like mobile data, wifi, hotspot &
sharing data etc.
• Window
It can handle the multiple windows in our device. For example
symultantously while listing the songs chatting with some one so its
handling two two different windows at a time like same some windows
cache memory & browser windows etc.
Many of the android componnts and servicew are build from native code
those android runtime & Hardware abstraction layers because native
libraries wriiten in C & C++.
• Webkit
• Open Max AL
• Libc
Lot of componets are developed by C & C++ so it always requied
support of Libc.
• Meida framework
Android apps can support all type of media like jpg, png, mp3, mp4 etc.
• Open GLES
From android 5.0 and above version of android with its own process and
its own instance of Android Runtime. ART is designed for low memory
device by excuting the DEX (byte code) files to run on virtual
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
70 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
Note:
Previosly Lower version (less than 5.0) is run in Dalvik virtual machine,
now as well as it can run in ART also, then it can run DVM as well, but
vicevera is not possible.
• Core Librariries
Android application also includes a set of core libraries that provide most
of the runtime functionality of the Java programming language, and it
includes android 8.0 features as well
1. Linux Kernel
Linux kernel is hardware layer. For example, the ART relies on the Linux
kernel for functionalities such as threading and low-level memory
management. Linux kernel allows Android to take advantage of key
features like develop hardware drivers for a well-known kernel such as
Audio, Keypad, Shraed memory, Usb, Bluetooth, Binder(IPC)Display,
Camera, Wifi, Power Management etc.
Button:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="androindian.MainActivity">
<TextView
android:layout_width="match_parent"
import androidx.appcompat.app.AppCompatActivity
import android.widget.TextView
import android.os.Bundle
import android.view.View
import android.widget.Button
import com.androinidan.button.R
CHECKBOX
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
75 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
• Appearance:
• A CheckBox typically consists of a square or rectangular box
followed by a label (text).
• When checked, a checkmark or a tick appears inside the box
to indicate the selection.
• When unchecked, the box remains empty.
• Usage:
• CheckBoxes are commonly used in forms, settings screens,
and lists where users need to make multiple selections.
• They are useful for allowing users to specify preferences,
select items from a list, or indicate agreement to terms and
conditions.
• Attributes:
• CheckBoxes can be customized using various attributes to
control their appearance and behavior.
• Common attributes include text (label), checked state, text
color, text size, padding, background, etc.
• You can also specify an optional listener to be notified when
the CheckBox state changes, allowing you to perform actions
based on user interactions.
• Interactivity:
• CheckBoxes respond to user input by toggling between the
checked and unchecked states when clicked.
• They can be configured to be either checked or unchecked
by default.
• When used in groups (such as within a CheckBox group),
multiple CheckBoxes can be selected simultaneously.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
76 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF5722"
android:textSize="30sp"
android:textStyle="bold"
android:textAllCaps="true"
android:padding="10dp"
android:layout_margin="10dp"
android:gravity="center"
android:layout_gravity="center"
android:id="@+id/tv1"
/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Android"
android:textColor="#FF5722"
android:textSize="30sp"
android:textStyle="bold"
android:textAllCaps="true"
android:padding="10dp"
android:layout_margin="10dp"
android:gravity="center"
android:layout_gravity="center"
android:id="@+id/check"
></CheckBox>
</LinearLayout>
MainActivity.kt
package com.androinidan.checkboxkotlin
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.CheckBox
import android.widget.CompoundButton
import android.widget.Switch
import android.widget.TextView
import android.widget.ToggleButton
tv = findViewById(R.id.tv1)
check = findViewById(R.id.check)
check!!.setOnClickListener{
if(check!!.isChecked)
tv!!.text=("Checked")
else
tv!!.text=("UnChecked")
TOGGLE BUTTON
A ToggleButton in Android is a UI element that represents a two-state
button, similar to a physical toggle switch. It allows users to toggle
between two states, typically "on" and "off" or "checked" and
"unchecked". ToggleButtons are useful for enabling or disabling a
feature, activating or deactivating a setting, or switching between two
modes.
Here are some key points about ToggleButtons in Android:
• Appearance:
• A ToggleButton typically consists of a rectangular button with
two states: pressed (activated) and unpressed (deactivated).
• The button's appearance changes to indicate its current
state, often with a different background color or visual
indicator.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF5722"
android:textSize="30sp"
android:textStyle="bold"
android:textAllCaps="true"
android:padding="10dp"
android:layout_margin="10dp"
android:gravity="center"
android:layout_gravity="center"
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
79 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
android:id="@+id/tv1"
/>
<ToggleButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#FF5722"
android:textSize="30sp"
android:textStyle="bold"
android:textAllCaps="true"
android:padding="10dp"
android:layout_margin="10dp"
android:gravity="center"
android:layout_gravity="center"
android:id="@+id/toggle"></ToggleButton>
</LinearLayout>
MainActivity.kt
package com.androinidan.checkboxkotlin
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.CheckBox
import android.widget.CompoundButton
import android.widget.Switch
import android.widget.TextView
import android.widget.ToggleButton
tv = findViewById(R.id.tv1)
toogle=findViewById(R.id.toggle)
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
80 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
toogle!!.setOnClickListener{
if(toogle!!.isChecked)
tv!!.text=("TON")
else
tv!!.text=("TOFF")
}
SWITCH
a Switch is a UI element that allows users to toggle between two states -
typically "on" and "off". It's similar to a ToggleButton but has a more
modern and compact design, resembling a physical switch.
Here are some key points about Switches in Android:
• Appearance:
• A Switch consists of a small rectangular track and a thumb
(also called a handle or knob) that slides horizontally along
the track.
• The thumb's position indicates the current state of the
Switch: to the left for "off" and to the right for "on".
• The track's color or appearance often changes to indicate the
active and inactive states.
• Usage:
• Switches are commonly used in settings screens, control
panels, and other parts of the user interface where users
need to quickly switch between two states.
• They provide a clear and intuitive way for users to enable or
disable a feature, activate or deactivate a setting, or switch
between two modes.
• Attributes:
• Switches can be customized using various attributes to
control their appearance and behavior.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF5722"
android:textSize="30sp"
android:textStyle="bold"
android:textAllCaps="true"
android:padding="10dp"
android:layout_margin="10dp"
android:gravity="center"
android:layout_gravity="center"
android:id="@+id/tv1"
/>
<Switch
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Switch"
android:textColor="#FF5722"
android:textSize="30sp"
android:textStyle="bold"
android:textAllCaps="true"
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
82 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
android:padding="10dp"
android:layout_margin="10dp"
android:gravity="center"
android:layout_gravity="center"
android:id="@+id/switch1"></Switch>
</LinearLayout>
MainActivity.kt
package com.androinidan.checkboxkotlin
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.CheckBox
import android.widget.CompoundButton
import android.widget.Switch
import android.widget.TextView
import android.widget.ToggleButton
tv = findViewById(R.id.tv1)
swit=findViewById(R.id.switch1)
swit!!.setOnClickListener{
if(swit!!.isChecked)
tv!!.text=("SON")
else
tv!!.text=("SOFF")
}
}
• RadioGroup:
• A RadioGroup is a layout container used to hold multiple
RadioButton elements.
• It ensures that only one RadioButton within the group can be
selected at a time, enforcing mutual exclusivity.
• When a RadioButton is selected within a RadioGroup, any
previously selected RadioButton within the same group is
automatically deselected.
• RadioButtons within the same RadioGroup are typically
aligned vertically or horizontally, depending on the layout
configuration.
• RadioGroups are commonly used in forms, questionnaires,
and settings screens where users need to make a single
selection from a list of options.
• RadioButton:
• A RadioButton is a UI element that represents a single
choice in a set of mutually exclusive options.
• It typically consists of a circular button followed by a label
(text).
• When selected, a dot or circle appears inside the button to
indicate the selection.
• RadioButton elements are placed within a RadioGroup to
ensure mutual exclusivity.
• RadioButtons are commonly used in conjunction with
RadioGroups to allow users to select one option from a list of
choices.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
84 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF5722"
android:textSize="30sp"
android:textStyle="bold"
android:textAllCaps="true"
android:padding="10dp"
android:layout_margin="10dp"
android:gravity="center"
android:layout_gravity="center"
android:id="@+id/tv1"
/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/rg">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/r1"
android:text="Male"></RadioButton>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/r2"
android:text="Female"></RadioButton>
</RadioGroup>
</LinearLayout>
MainActivity.kt
package com.androinidan.checkboxkotlin
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.CheckBox
import android.widget.CompoundButton
import android.widget.RadioButton
tv = findViewById(R.id.tv1)
radiogroup=findViewById(R.id.rg)
r1=findViewById(R.id.r1)
}
}
SEEKBAR
A SeekBar in Android is a UI element that allows users to select a value
within a specified range by sliding a thumb along a horizontal or vertical
track. SeekBars are commonly used for tasks such as adjusting volume,
seeking through media playback, or setting progress indicators.
Here are some key points about SeekBars in Android:
• Appearance:
• A SeekBar consists of a track and a thumb (also known as a
slider or handle).
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="26dp"
android:max="10"/>
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
87 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/seekBar1"
android:layout_marginLeft="29dp"
android:layout_marginTop="14dp" />
</RelativeLayout>
MainActivity.kt
package com.androidian.seekbar
import android.os.Bundle
import android.view.View
import android.widget.SeekBar
import android.widget.SeekBar.OnSeekBarChangeListener
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
RATING BAR
A RatingBar in Android is a UI element that allows users to provide a
rating or feedback by selecting a number of stars from a predefined
range. It is commonly used in apps where users are asked to rate
products, services, or content.
Here are some key points about RatingBars in Android:
• Appearance:
• A RatingBar consists of a row of stars or other symbols
representing the rating scale.
• Each star can be filled (selected) or empty (unselected),
indicating the user's rating.
• The number of stars displayed represents the rating scale's
range, typically from 0 to 5.
• Depending on the configuration, users can either tap on
individual stars or swipe across the RatingBar to select their
rating.
• Usage:
• RatingBars are commonly used in review systems, feedback
forms, product ratings, and other parts of the user interface
where users need to provide a numerical rating.
• They provide a simple and intuitive way for users to express
their opinions or preferences by selecting a number of stars.
• Attributes:
• RatingBars can be customized using various attributes to
control their appearance and behavior.
• Common attributes include the number of stars, star size,
star spacing, star color (selected and unselected), and the
initial rating value.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio Button Example"
android:textAllCaps="true"
android:textStyle="italic"
android:textSize="20sp"
android:textColor="#309"
android:padding="5dp"
android:layout_margin="5dp"
android:id="@+id/tv1"/>
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stepSize="1"/>
</LinearLayout>
MainActivity.kt
package com.androinidan.radiobutton
import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
90 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
import android.os.Bundle
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.RadioGroup
import android.widget.RatingBar
import android.widget.TextView
import android.widget.Toast
ratingbar = findViewById(R.id.ratingBar)
IMAGE BUTTON
An ImageButton in Android is a UI element that displays a clickable
image. It's essentially a button with an image instead of text.
ImageButton allows users to perform actions or trigger events when the
image is clicked.
Here are some key points about ImageButtons in Android:
• Appearance:
• An ImageButton displays an image as its content instead of
text.
• The image can be any drawable resource, such as PNG,
JPG, SVG, etc.
• ImageButton supports both fixed and adjustable sizes,
depending on the layout configuration.
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
91 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio Button Example"
android:textAllCaps="true"
android:textStyle="italic"
android:textSize="20sp"
android:textColor="#309"
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
92 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
android:padding="5dp"
android:layout_margin="5dp"
android:id="@+id/tv1"/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ib"
android:src="@mipmap/download"></ImageButton>
</LinearLayout>
MainActivity.kt
package com.androinidan.radiobutton
import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.RadioGroup
import android.widget.RatingBar
import android.widget.TextView
import android.widget.Toast
@SuppressLint("WrongConstant")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
ib=findViewById(R.id.ib)
ib!!.setOnClickListener{
Toast.makeText(applicationContext,"You seletcd imagebutton",5000).show()
}
}
}
IMAGEVIEW
An ImageView in Android is a UI element used to display images within
an app's user interface. It's one of the most commonly used widgets for
showing images, whether they are loaded from resources within the app
or fetched dynamically from external sources like the internet.
Here are some key points about ImageViews in Android:
• Appearance:
• An ImageView displays a single image, which can be loaded
from various sources such as drawables, files, URIs, or
network URLs.
• The image can be displayed using various scale types, such
as center-crop, fit-center, center-inside, etc., to control how it
fits within the ImageView's boundaries.
• ImageView supports both fixed and adjustable sizes,
depending on the layout configuration.
• The appearance of the ImageView can be customized using
various attributes, including padding, background, scale type,
etc.
• Usage:
• ImageViews are used to show images within the app's UI,
such as photos, icons, logos, thumbnails, etc.
• They are versatile and can be used in a wide range of
scenarios, including image galleries, profile pictures, product
listings, and more.
• ImageViews can be placed anywhere in the layout, including
within ViewGroup containers like LinearLayout,
RelativeLayout, ConstraintLayout, etc.
• Attributes:
• ImageViews can be customized using various attributes to
control their appearance and behavior.
• Common attributes include the image source (src), scale
type, background color, padding, visibility, etc.
• You can load images into an ImageView programmatically
using methods like setImageResource(),
setImageDrawable(), setImageBitmap(), or by using libraries
like Picasso or Glide for more advanced image loading and
caching capabilities.
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
94 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
• Interactivity:
• ImageViews are typically static and don't respond to user
input by default.
• However, you can make them interactive by combining them
with other UI elements, such as Buttons or ClickListeners, to
perform actions when clicked.
• For example, you can wrap an ImageView inside a Button or
use it as a background for a Button to create a clickable
image button.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio Button Example"
android:textAllCaps="true"
android:textStyle="italic"
android:textSize="20sp"
android:textColor="#309"
android:padding="5dp"
android:layout_margin="5dp"
android:id="@+id/tv1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/iv"
android:src="@mipmap/download"></ImageView>
</LinearLayout>
MainActivity.kt
package com.androinidan.radiobutton
import android.annotation.SuppressLint
@SuppressLint("WrongConstant")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
iv=findViewById(R.id.iv)
iv!!.setOnClickListener{
Toast.makeText(applicationContext,"You seletd
image",Toast.LENGTH_LONG).show()
}
}
}
TEXT FIELDS
EditText is a user interface element used for capturing user input in the
form of text. It allows users to enter and edit text interactively on the
screen. EditTexts are commonly used in forms, input fields, search bars,
chat interfaces, and other parts of the user interface where textual input
is required.
• Appearance:
• An EditText appears as a rectangular input field where users
can type text.
• The appearance of the EditText can be customized using
various attributes such as text size, text color, background
color, hint text, etc.
• EditTexts can be single-line or multi-line, depending on the
input requirements.
• Usage:
• EditTexts are used to collect textual input from users, such
as names, email addresses, passwords, comments, etc.
• They support a wide range of input types, including text,
numbers, dates, email addresses, phone numbers, and
more.
• EditTexts can be placed anywhere in the layout, including
within ViewGroup containers like LinearLayout,
RelativeLayout, ConstraintLayout, etc.
• Attributes:
• EditTexts can be customized using various attributes to
control their appearance and behavior.
• Common attributes include text size, text color, hint text
(placeholder text displayed when the EditText is empty),
input type (text, number, email, password, etc.), background
color, padding, etc.
• Interactivity:
• EditTexts respond to user input by allowing users to type text
using the on-screen keyboard.
• They provide features such as auto-capitalization, auto-
correction, spell-checking, and suggestions (depending on
the device's keyboard settings).
• You can programmatically retrieve the text entered into an
EditText using the text property or listen for changes using a
TextWatcher.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
97 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Example Form"
android:textColor="#E91E63"
android:textSize="20sp"
android:textStyle="italic"
android:textAllCaps="true"
android:layout_margin="5dp"
android:padding="5dp"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<EditText
android:id="@+id/editTextTextPersonName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:hint="textPersonName"
android:textColor="#E91E63"
android:textSize="20sp"
android:textStyle="italic"
android:textAllCaps="true"
android:layout_margin="5dp"
android:padding="5dp"
android:textColorHint="#3F51B5"/>
<EditText
android:id="@+id/editTextTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
98 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
android:hint="textPassword"
android:textColor="#E91E63"
android:textSize="20sp"
android:textStyle="italic"
android:textAllCaps="true"
android:layout_margin="5dp"
android:padding="5dp"
android:textColorHint="#3F51B5"/>
<EditText
android:id="@+id/editTextNumberPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberPassword"
android:hint="numberPassword"
android:textColor="#E91E63"
android:textSize="20sp"
android:textStyle="italic"
android:textAllCaps="true"
android:layout_margin="5dp"
android:padding="5dp"
android:textColorHint="#3F51B5"/>
<EditText
android:id="@+id/editTextTextEmailAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress"
android:hint="textEmailAddress"
android:textColor="#E91E63"
android:textSize="20sp"
android:textStyle="italic"
android:textAllCaps="true"
android:layout_margin="5dp"
android:padding="5dp"
android:textColorHint="#3F51B5"/>
<EditText
android:id="@+id/editTextTextMultiLine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:gravity="start|top"
android:inputType="textMultiLine"
android:textColor="#E91E63"
android:textSize="20sp"
android:textStyle="italic"
android:textAllCaps="true"
<EditText
android:id="@+id/editTextTextPostalAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPostalAddress"
android:hint="textPostalAddress"
android:textColor="#E91E63"
android:textSize="20sp"
android:textStyle="italic"
android:textAllCaps="true"
android:layout_margin="5dp"
android:padding="5dp"
android:textColorHint="#3F51B5"/>
<EditText
android:id="@+id/editTextTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="time"
android:hint="time"
android:textColor="#E91E63"
android:textSize="20sp"
android:textStyle="italic"
android:textAllCaps="true"
android:layout_margin="5dp"
android:padding="5dp"
android:textColorHint="#3F51B5"/>
<EditText
android:id="@+id/editTextNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
android:hint="number"
android:textColor="#E91E63"
android:textSize="20sp"
android:textStyle="italic"
android:textAllCaps="true"
android:layout_margin="5dp"
android:padding="5dp"
android:textColorHint="#3F51B5"/>
<EditText
android:id="@+id/editTextNumberSigned"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberSigned"
android:hint="numberSigned"
android:textColor="#E91E63"
android:textSize="20sp"
android:textStyle="italic"
android:textAllCaps="true"
android:layout_margin="5dp"
android:padding="5dp"
android:textColorHint="#3F51B5"/>
<EditText
android:id="@+id/editTextNumberDecimal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal"
android:hint="numberDecimal"
android:textColor="#E91E63"
android:textSize="20sp"
android:textStyle="italic"
android:textAllCaps="true"
android:layout_margin="5dp"
android:padding="5dp"
android:textColorHint="#3F51B5"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bt"
android:text="Submit"></Button>
</LinearLayout>
</ScrollView>
</LinearLayout>
MainActivity.kt
package com.androinidan.form
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
button=findViewById(R.id.bt)
e1=findViewById(R.id.editTextTextPersonName)
e2=findViewById(R.id.editTextTextPassword)
button!!.setOnClickListener {
}
}
}
COMPONENTS OF ANDROID
ACTIVITY LIFE CYCLE
An activity is a single, focused thing that the user can do. Almost all
activities interact with the user, so the Activity class takes care of
creating a window for you in which you can place your UI with
setContentView(View). While activities are often presented to the user
as full-screen windows, they can also be used in other ways: as floating
windows (via a theme with windows Floating set) or embedded inside of
another activity (using ActivityGroup). There are two methods almost all
subclasses of Activity will implement:
onPause() is where you deal with the user leaving your activity. Most
importantly, any changes made by the user should at this point be
committed (usually to the ContentProvider holding the data).
To be of use with Context.startActivity(), all activity classes must have a
corresponding <activity> declaration in their package’s
AndroidManifest.xml
Activities in the system are managed as an activity stack. When a new
activity is started, it is placed on the top of the stack and becomes the
running activity — the previous activity always remains below it in the
stack, and will not come to the foreground again until the new activity
exits.
An activity has essentially four states:
If an activity is in the foreground of the screen (at the top of the stack), it
is active or running.
If an activity has lost focus but is still visible (that is, a new non-full-sized
or transparent activity has focus on top of your activity), it is paused. A
paused activity is completely alive (it maintains all state and member
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
103 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(MainActivity.this,
"Oncreate",Toast.LENGTH_LONG).show();
Log.i("result","Create");
}
protected void onStop(){
super.onStop();
Toast.makeText(MainActivity.this,
"OnStop",Toast.LENGTH_LONG).show();
Log.i("result","OnStop");
}
protected void onStart(){
super.onStart();
Toast.makeText(MainActivity.this,
"onStart",Toast.LENGTH_LONG).show();
Log.i("result","onStart");
}
SERVICES
A Service is an app component that can handle long-running operations
perform file I/O, or interact with a content provider, all from the
background.
Scheduled
introduced in Android 5.0 (API level 21), launches the service. You can
conditions.
Note: If your app targets Android 5.0 (API level 21), Google recommends
more information about using this class, see the JobScheduler reference
documentation.
Started
calls startService(). After it’s started, a service can run in the background
started service performs a single operation and does not return a result
to the caller.
For example, it can download or upload a file over the network. When
Bound
application) in the same way that any component can use an activity—by
starting it with an Intent. However, you can declare the service as private
in the manifest file and block access from other applications. This is
manifest.
Caution: A service runs in the main thread of its hosting process; the
service does not create its own thread and does not run in a separate
complete that work. By using a separate thread, you can reduce the risk
Activity_mai.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Services Example"
/>
<Button
android:id="@+id/start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Start Servie" />
<Button
android:id="@+id/stop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Stop Services" />
</LinearLayout>
</layout>
MainActivity.kt
package com.androindian.services
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import com.androindian.services.databinding.ActivityMainBinding
bining?.stop?.setOnClickListener {
var intent= Intent(this,Myservices::class.java)
stopService(intent)
}
}
}
Myservices.kt
package com.androindian.services
import android.app.Service
import android.content.Intent
import android.os.IBinder
import android.widget.Toast
BROADCAST RECEIVERS
a BroadcastReceiver is a component that allows an app to listen for and
respond to system-wide broadcast messages or events. These events
could originate from the system itself, such as when the device boots up,
when the battery level changes, when the network connectivity state
changes, etc. Additionally, apps can send custom broadcasts to
communicate within the app or between different apps.
Here are some key points about BroadcastReceivers in Android:
• Purpose:
• BroadcastReceivers allow apps to receive and respond to
broadcast messages sent by the system or other apps.
• They provide a way for apps to be notified of important
system events or changes and to perform actions in
response.
• Types of Broadcasts:
• There are two main types of broadcasts in Android: system
broadcasts and custom broadcasts.
• System broadcasts are sent by the system to notify apps of
system events, such as the device booting up, the battery
level changing, the network connectivity state changing, etc.
• Custom broadcasts are broadcasts sent by apps to
communicate within the app or between different apps.
• Registration:
• BroadcastReceivers can be registered either statically in the
AndroidManifest.xml file or dynamically at runtime using
code.
• Static registration in the manifest is used for system-wide
broadcasts or broadcasts that need to be received even
when the app is not running.
Activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<EditText android:id="@+id/extraIntent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/sendMessage" />
<Button
android:id="@+id/btnStartBroadcast"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/extraIntent"
android:onClick="broadcastCustomIntent"
android:text="@string/myBroadcastIntent" />
</RelativeLayout>
MainActivity.Java
package androidindians.broadcastreciver
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.widget.EditText
MyBroadcastReceiver.java
package androidindians.broadcastreciver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.widget.Toast
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="androiindians.broadcastreciver">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
114 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="MyBroadcastReceiver">
<intent-filter>
<action android:name="androiindians.broadcastreciver.A_CUSTOM_INTENT">
</action>
</intent-filter>
</receiver>
</application>
</manifest>
Strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">BroadcastReceiversTest</string>
<string name="action_settings">Settings</string>
<string name="sendMessage">Write a message to broadcast!</string>
<string name="myBroadcastIntent">Broadcast an Intent now...</string>
</resources>
CONTENT PROVIDER
A Content Provider in Android is a component that manages access to a
central repository of data. It acts as an intermediary between different
applications, allowing them to share and access data in a consistent and
secure manner. Content Providers are commonly used to manage
structured data stored in databases, files, or other data sources.
Here's an explanation of Content Providers along with an example code
in Kotlin:
• Purpose:
• Content Providers facilitate data sharing between different
applications in Android.
• They provide a standardized interface for querying, inserting,
updating, and deleting data.
• Content Providers ensure data integrity and security by
enforcing access permissions and data encapsulation.
• Components:
• URI (Uniform Resource Identifier): Content Providers use
URIs to identify data resources. URIs typically have the
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
115 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
Example Code:
• Let's create a simple Content Provider in Kotlin that manages a list
of books. We'll define a contract class that specifies the data
schema, a Content Provider class that implements the CRUD
operations, and use a SQLite database to store the data.
// BookContract.kt
object BookContract {
const val CONTENT_AUTHORITY = "com.example.bookprovider"
const val PATH_BOOKS = "books"
val CONTENT_URI: Uri = Uri.parse("content://$CONTENT_AUTHORITY/$PATH_BOOKS")
object BookEntry {
const val TABLE_NAME = "books"
const val COLUMN_ID = "_id"
const val COLUMN_TITLE = "title"
const val COLUMN_AUTHOR = "author"
}
}
// BookProvider.kt
class BookProvider : ContentProvider() {
private lateinit var dbHelper: BookDbHelper
// BookDbHelper.kt
class BookDbHelper(context: Context) : SQLiteOpenHelper(context, DATABASE_NAME, null,
DATABASE_VERSION) {
override fun onCreate(db: SQLiteDatabase) {
val SQL_CREATE_BOOKS_TABLE = "CREATE TABLE
${BookContract.BookEntry.TABLE_NAME} (" +
"${BookContract.BookEntry.COLUMN_ID} INTEGER PRIMARY KEY AUTOINCREMENT, "
+
"${BookContract.BookEntry.COLUMN_TITLE} TEXT NOT NULL, " +
"${BookContract.BookEntry.COLUMN_AUTHOR} TEXT NOT NULL);"
db.execSQL(SQL_CREATE_BOOKS_TABLE)
}
companion object {
private const val DATABASE_NAME = "books.db"
private const val DATABASE_VERSION = 1
}
}
In this example:
INTENTS
an Intent is a messaging object that facilitates communication between
components of an application, as well as between different applications.
Intents are used for various purposes, including starting activities,
services, and broadcasts, as well as passing data between components.
Here's an explanation of Intents in Android:
• Purpose:
• Intents are used to initiate various actions within an Android
application or between different applications.
• They provide a flexible and loosely coupled way for
components to communicate with each other.
• Intents enable developers to create dynamic and interactive
user experiences by launching activities, starting services,
broadcasting messages, and passing data.
• Types:
• Explicit Intents: Explicit Intents are used to start a specific
component within the same application by specifying the
target component's class name or package name.
• Implicit Intents: Implicit Intents are used to trigger an action
based on the intent's action string, such as opening a web
page, sending an email, making a phone call, or sharing
content with other apps. Implicit Intents allow the system to
find the best matching component to handle the requested
action.
• Components:
• Activities: Intents are commonly used to start activities, which
represent individual screens in an Android application. By
using Intents, developers can navigate between different
activities within the same app or launch activities from other
apps.
• Services: Intents can also be used to start background
services, which perform long-running operations in the
background, such as downloading files, playing music, or
processing data.
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
118 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
Activity_main.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="We are in First Page"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/name"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/mobile"/>
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
119 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Move to Second"
android:id="@+id/bt1"
/>
</LinearLayout>
</layout>
MainActivity.kt
package com.example.exintent
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import com.example.exintent.databinding.ActivityMainBinding
binding?.bt1?.setOnClickListener{
var intent= Intent(this@MainActivity,Second::class.java)
// intent.putExtra("key","values")
intent.putExtra("name",binding?.name?.text.toString())
intent.putExtra("mobile",binding?.mobile?.text.toString())
startActivity(intent)
}
}
}
Activity_second.kt
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Second"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="We are in Second Page"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Move to Third"
android:id="@+id/bt2"
/>
</LinearLayout>
</layout>
SecondActivity.kt
package com.example.exintent
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import com.example.exintent.databinding.ActivitySecondBinding
binding=
DataBindingUtil.setContentView(this,R.layout.activity_second)
var dataintent=intent
var s1=dataintent.getStringExtra("name")
var s2=dataintent.getStringExtra("mobile")
Toast.makeText(this@Second,""+s1+s2,Toast.LENGTH_LONG).sh
ow()
binding?.bt2?.setOnClickListener {
var intent= Intent(this@Second,Third::class.java)
intent.putExtra("data",s1+s2)
startActivity(intent)
// finish()
}
}
}
Activity_third.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Third">
</androidx.constraintlayout.widget.ConstraintLayout>
ThirdActivity.kt
package com.example.exintent
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_third)
var dataintent=intent
var s1=dataintent.getStringExtra("data")
Toast.makeText(this@Third,""+s1, Toast.LENGTH_LONG).show()
Androidmanifest.xml
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Exintent"
tools:targetApi="31">
<activity
android:name=".Third"
android:exported="false" />
<activity
android:name=".Second"
android:exported="false" />
<activity
android:name=".MainActivity"
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
123 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
</manifest>
Activity_main.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Implicit Intent eaxmple!"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Camera "
android:id="@+id/camera"/>
<Button
android:layout_width="match_parent"
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
124 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
android:layout_height="wrap_content"
android:text="Browser "
android:id="@+id/browser"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Gallary "
android:id="@+id/gallary"/>
</LinearLayout>
</layout>
MainActivity.kt
package com.example.implicit
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.provider.MediaStore
import androidx.databinding.DataBindingUtil
import com.example.implicit.databinding.ActivityMainBinding
import android.content.Intent
import android.net.Uri
binding?.camera?.setOnClickListener {
intent.data=Uri.parse("https://androindian.com/registration-using-
retrofit-raw-data/")
startActivity(intent)
}
binding?.gallary?.setOnClickListener {
startActivity(intent)
}
}
• PURPOSE:
• ADAPTERS ARE USED TO BIND DATA TO UI COMPONENTS ,
ALLOWING THEM TO DISPLAY INFORMATION FROM A DATA
SOURCE.
• THEY ABSTRACT AWAY THE COMPLEXITY OF MANAGING DATA
PRESENTATION , HANDLING DATA UPDATES , AND RECYCLING
VIEWS TO OPTIMIZE MEMORY USAGE AND PERFORMANCE .
• TYPES OF ADAPTERS:
• ARRAYADAPTER: ARRAYADAPTER IS A SIMPLE ADAPTER THAT
WORKS WITH ARRAYS OR LISTS OF DATA . IT CONVERTS EACH
LISTVIEW EXAMPLE
Activity_main.xml
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/list"/>
</LinearLayout>
</layout>
MainActivity.kt
package com.example.list
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import com.example.list.databinding.ActivityMainBinding
//var courseadapter=
ArrayAdapter(this@MainActivity,R.layout.custom, Course)
//binding?.list?.adapter=courseadapter
android:textSize="20sp"
android:layout_margin="10dp"
android:padding="10dp">
</TextView>
String.xml
<resources>
<string name="app_name">List</string>
<string-array name="xyz">
<item>abc</item>
<item>abc</item>
<item>abc</item>
<item>abc</item>
<item>abc</item>
<item>abc</item>
<item>abc</item>
<item>abc</item>
<item>abc</item>
<item>abc</item>
<item>abc</item>
</string-array>
</resources>
GRIDVIEW EXAMPLE
Activity_main.xml
<GridView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/grid"
android:layout_margin="10dp"
android:numColumns="auto_fit"/>
</RelativeLayout>
</layout>
MainActivity.kt
package com.example.grid
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.AdapterView
import android.widget.AdapterView.OnItemSelectedListener
import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import com.example.grid.databinding.ActivityMainBinding
Toast.makeText(this,""+id,Toast.LENGTH_LONG).show()
}
}
}
SPINNER EXAMPLE
Activity_main.xml
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/spin"
android:layout_below="@id/grid"
android:layout_margin="10dp"/>
</RelativeLayout>
</layout>
MainActivity.kt
package com.example.grid
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.AdapterView
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
132 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
import android.widget.AdapterView.OnItemSelectedListener
import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import com.example.grid.databinding.ActivityMainBinding
binding?.spin?.setOnItemSelectedListener(object:
OnItemSelectedListener{
override fun onItemSelected(
parent: AdapterView<*>?,
view: View?,
position: Int,
id: Long
){
Toast.makeText(this@MainActivity,""+id,Toast.LENGTH_LON
G).show()
}
}
})
}
}
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
133 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
AUTOCOMPLETETEXTVIEW EXAMPLE
Activity_main.xml
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/auto"
android:layout_below="@id/spin"
android:completionThreshold="1"
android:layout_margin="10dp"/>
</RelativeLayout>
</layout>
MainActivity.kt
package com.example.grid
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.AdapterView
import android.widget.AdapterView.OnItemSelectedListener
import android.widget.ArrayAdapter
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
134 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import com.example.grid.databinding.ActivityMainBinding
RECYCLERVIEW
RecyclerView is a powerful and flexible UI component introduced in
Android's support library to efficiently display large datasets in a
scrollable list or grid format. It's an improved version of the older
ListView and GridView components, providing better performance, more
flexibility, and easier customization.
Here's an explanation of RecyclerView in Android:
• Purpose:
• RecyclerView is designed to efficiently display large datasets
in a scrollable list or grid format.
• It efficiently manages the memory usage by recycling views
as they move off-screen, reducing the need for creating and
destroying views dynamically.
• RecyclerView provides a flexible architecture for
implementing various layout managers, item decorations,
and item animations.
• Components:
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
135 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
Build.gradle
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
136 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
}
android {
namespace = "com.example.recycler"
compileSdk = 34
defaultConfig {
applicationId = "com.example.recycler"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner =
"androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
dataBinding{
enable=true
}
}
dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-
core:3.5.1")
}
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<layout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Recycler view example"
android:id="@+id/tv1"
/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rec"
android:layout_below="@id/tv1"
android:layout_margin="10dp"/>
</RelativeLayout>
</layout>
MainActivity.kt
package com.example.recycler
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
138 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.recycler.databinding.ActivityMainBinding
CustomAdapter.kt
package com.example.recycler
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
139 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
import android.widget.TextView
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
init {
adpnames=names
adpemail=emails
adpmobile=mobile
adpprofile=profile
adpContext=mainActivity
}
holder.name?.text=adpnames[holder.adapterPosition]
holder.email?.text=adpemail[holder.adapterPosition]
holder.mobile?.text=adpmobile[holder.adapterPosition]
holder.profile?.setImageResource(adpprofile[holder.adapterPosition]
)
holder?.profile?.setOnClickListener{
Toast.makeText(adpContext,"image"+position,Toast.LENGTH_L
ONG).show()
}
holder?.linearLayout?.setOnClickListener{
Toast.makeText(adpContext,"adp"+position,Toast.LENGTH_LON
G).show()
}
}
init {
name=itemview.findViewById(R.id.name)
mobile=itemview.findViewById(R.id.mobile)
email=itemview.findViewById(R.id.email)
profile=itemview.findViewById(R.id.iv)
linearLayout=itemview.findViewById(R.id.linear)
Custom.xml
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/iv"
android:layout_margin="5dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linear"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/name"
android:layout_margin="5dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/mobile"
android:layout_margin="5dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/email"
android:layout_margin="5dp"/>
</LinearLayout>
</LinearLayout>
TELEPHONY MANAGER
IMEI
import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.telephony.TelephonyManager
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
arrayOf(Manifest.permission.READ_PHONE_STATE),
REQUEST_READ_PHONE_STATE
)
} else {
getIMEINumber()
}
} else {
getIMEINumber()
}
}
if (requestCode == REQUEST_READ_PHONE_STATE) {
if (grantResults.isNotEmpty() && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
getIMEINumber()
} else {
Toast.makeText(
this,
"Permission denied. IMEI cannot be retrieved.",
Toast.LENGTH_SHORT
).show()
}
}
}
if (imei != null) {
Toast.makeText(this, "IMEI number: $imei",
Toast.LENGTH_LONG).show()
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
144 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
} else {
Toast.makeText(this, "IMEI number not available",
Toast.LENGTH_LONG).show()
}
}
}
PHONE STATUS
Activity_main.xml
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="vertical">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ringer"
android:layout_margin="16dp"/>
<Button
android:id="@+id/button2"
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
145 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Vibrate "
android:layout_margin="16dp"/>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Silent "
android:layout_margin="16dp"/>
</androidx.cardview.widget.CardView>
</LinearLayout>
</LinearLayout>
</layout>
MainActivity.kt
package com.example.phonestatus
import android.content.Context
import android.media.AudioManager
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import com.example.phonestatus.databinding.ActivityMainBinding
audioManager=getSystemService(Context.AUDIO_SERVICE) as
AudioManager?
binding?.button1?.setOnClickListener{
audioManager?.ringerMode=AudioManager.RINGER_MODE_NO
RMAL
}
binding?.button1?.setOnClickListener{
audioManager?.ringerMode=AudioManager.RINGER_MODE_VI
BRATE
}
binding?.button3?.setOnClickListener{
audioManager?.ringerMode=AudioManager.RINGER_MODE_SIL
ENT
}
}
}
Bluetooth
Add Bluetooth Permissions:
• First, you need to add the necessary permissions to your
AndroidManifest.xml file.
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
Enable Bluetooth:
• You may need to enable Bluetooth if it's not already enabled.
private fun enableBluetooth() {
val bluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
if (!bluetoothAdapter.isEnabled) {
val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT)
}
}
DIALOGS
dialogs are small UI components that overlay the current activity to
prompt the user for information or to confirm an action. There are several
types of dialogs available in Android, such as AlertDialog, CustomDialog,
DatePickerDialog, TimePickerDialog, etc.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dialogs Example"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Predefined"
android:id="@+id/preferined"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="custom"
android:id="@+id/custom"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="progress circle"
android:id="@+id/progress1"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Progress horizontal"
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
149 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
android:id="@+id/progress2"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/showdate"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pick date "
android:id="@+id/pickdate"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/showtime"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pick date "
android:id="@+id/picktime"/>
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</layout>
MainActivity.kt
package com.example.dialogs
import android.app.AlertDialog
import android.app.DatePickerDialog
import android.app.Dialog
import android.app.ProgressDialog
import android.app.TimePickerDialog
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
150 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.TimePicker
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import com.example.dialogs.databinding.ActivityMainBinding
import java.util.Calendar
binding?.preferined?.setOnClickListener{
var predefined= AlertDialog.Builder(this)
predefined.setTitle("Are you Sure")
predefined.setMessage("Want to Close")
predefined.setPositiveButton("Yes"){ dialogInterface,which->
Toast.makeText(this@MainActivity,"Yes",Toast.LENGTH_LON
G).show()
}
predefined.setNegativeButton("NO"){ dialogInterface,which->
Toast.makeText(this@MainActivity,"No",Toast.LENGTH_LON
G).show()
}
predefined.setNeutralButton("Cancel"){ dialogInterface,which->
Toast.makeText(this@MainActivity,"Cancel",Toast.LENGTH_L
ONG).show()
}
predefined.show()
}
binding?.custom?.setOnClickListener{
var dialog= Dialog(this)
dialog.setCancelable(false)
dialog.setContentView(R.layout.custom)
var bt: Button?=null
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
151 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
bt=dialog?.findViewById(R.id.button)
bt?.setOnClickListener{
dialog.dismiss()
Toast.makeText(this@MainActivity,"Button",Toast.LENGTH_L
ONG).show()
}
dialog.show()
}
binding?.progress1?.setOnClickListener {
var progressDialog=ProgressDialog(this@MainActivity)
progressDialog.setTitle("Please wait")
progressDialog.setMessage("Data laoding")
progressDialog.show()
}
binding?.progress2?.setOnClickListener {
var progressDialog=ProgressDialog(this@MainActivity)
progressDialog.setTitle("Please wait")
progressDialog.setMessage("Data laoding")
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZ
ONTAL)
progressDialog.show()
}
binding?.pickdate?.setOnClickListener{
datePickerDialog.getDatePicker().setMaxDate(System.currentTim
eMillis());
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
152 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
//
datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis(
));
datePickerDialog.show()
}
binding?.picktime?.setOnClickListener{
var caldender=Calendar.getInstance()
var mhour=caldender.get(Calendar.HOUR)
var mmin=caldender.get(Calendar.MINUTE)
var msec=caldender.get(Calendar.SECOND)
var timePickerDialog=TimePickerDialog(this@MainActivity,
object: TimePickerDialog.OnTimeSetListener{
},mhour,mmin,false)
timePickerDialog.show()
}
}
}
WEB SERVICES
Web services are software systems designed to support interoperable
machine-to-machine interaction over a network. They allow different
systems and applications to communicate with each other using
standard protocols and data formats. Web services are widely used for
• Purpose:
• Web services enable communication between different
software applications running on different platforms and
frameworks.
• They provide a standardized way for systems to interact and
exchange data over a network, regardless of the
programming language, operating system, or platform they
are built on.
• Web services facilitate the integration of heterogeneous
systems and the development of distributed and modular
applications.
• Key Characteristics:
• Interoperability: Web services use standard protocols and
data formats such as XML, JSON, SOAP, and REST to
ensure interoperability between different systems and
platforms.
• Loose Coupling: Web services promote loose coupling
between systems by decoupling the implementation details
of the service from its consumers. This allows for easier
maintenance, scalability, and evolution of the system.
• Platform Independence: Web services are platform-
independent, meaning they can be accessed and consumed
by any application regardless of the platform or technology
stack it is built on.
• Scalability: Web services can scale horizontally by adding
more instances of the service to handle increasing demand
and workload.
• TYPES OF WEB SERVICES:
• SOAP (Simple Object Access Protocol): SOAP is a protocol
for exchanging structured information in the implementation
of web services. It uses XML for message format and
typically runs over HTTP or SMTP.
• REST (Representational State Transfer): REST is an
architectural style for designing networked applications. It
relies on stateless communication and uses standard HTTP
methods (GET, POST, PUT, DELETE) for CRUD operations.
• Service Provider:
• The service provider is the entity responsible for
implementing and exposing the web service to potential
consumers.
• It develops the functionality and logic of the service, including
defining the service interface, implementing service
operations, and hosting the service on a server.
• The service provider publishes metadata about the service,
such as its interface definition and endpoint location, to allow
consumers to discover and access the service.
• Service Consumer:
• Data Format:
• Data format refers to the encoding and representation of
data exchanged between the service provider and consumer
during communication.
• Web services support various data formats, such as XML
(eXtensible Markup Language), JSON (JavaScript Object
Notation), and SOAP (Simple Object Access Protocol),
depending on the protocol and messaging format used.
• The choice of data format affects factors such as
interoperability, performance, and complexity of data
processing and serialization/deserialization.
• WEB SERVICES ADVANTAGES
Web services offer numerous advantages that make them a popular
choice for building distributed systems and enabling interoperable
communication between disparate applications and platforms. Here are
some key advantages of web services:
• Interoperability:
• Web services facilitate interoperable communication
between different systems and platforms, regardless of the
programming language, operating system, or hardware
infrastructure used.
• They use standard protocols and data formats such as
HTTP, XML, JSON, SOAP, and REST, enabling seamless
integration and data exchange between heterogeneous
environments.
• Platform Independence:
• Web services are platform-independent, allowing them to be
accessed and consumed by any application or system
regardless of the underlying technology stack.
• They enable organizations to build distributed systems that
can run on diverse platforms and infrastructures, including
desktops, mobile devices, cloud environments, and IoT
(Internet of Things) devices.
• Loose Coupling:
• Web services promote loose coupling between systems by
decoupling the implementation details of the service provider
from its consumers.
• They allow systems to interact and exchange data without
relying on specific implementation details, enabling easier
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
159 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
JSON
JSON (JavaScript Object Notation) is a lightweight data interchange
format that is easy for humans to read and write and easy for machines
to parse and generate. It is widely used as a format for transmitting data
between a server and a client in web applications, APIs, and various
other systems. JSON is language-independent and supported by most
programming languages and frameworks.
Here's an introduction to JSON:
• Data Format:
• JSON is a text-based data format that consists of key-value
pairs and arrays, organized in a hierarchical structure.
• It is based on two fundamental data structures: objects
(collection of key-value pairs enclosed in curly braces {}) and
arrays (ordered list of values enclosed in square brackets []).
• JSON supports basic data types such as strings, numbers,
booleans, null, objects, and arrays. It also allows nesting of
objects and arrays to represent complex data structures.
• Example:
{
"name": "John Doe",
"age": 30,
"isStudent": false,
"address": {
"street": "123 Main St",
"city": "Anytown",
"zipCode": "12345"
},
"interests": ["reading", "coding", "traveling"]
}
• Key Characteristics:
• Human Readable: JSON is designed to be easy for humans
to read and write, making it a popular choice for configuration
files, data serialization, and API responses.
• Lightweight: JSON has a simple and compact syntax, which
makes it lightweight and efficient for transmitting data over
the network.
• Language-Independent: JSON is language-independent and
can be parsed and generated by most programming
Overall, JSON is a versatile and widely adopted data format that offers
simplicity, readability, and interoperability, making it a popular choice for
transmitting and storing structured data in modern software
development. It provides a lightweight and flexible solution for
exchanging data between systems and applications in a variety of
contexts.
JSON ARCHITECTURE
JSON (JavaScript Object Notation) itself does not have a specific
architecture like web services or other software systems. Instead, it is a
lightweight data interchange format that is used to represent and
exchange structured data between systems. However, the use of JSON
within software architectures can be described in terms of how it fits into
the overall design and communication patterns of a system. Here's how
JSON typically fits into various software architectures:
• Client-Server Architecture:
TYPES OF WEBSERVICES
In the context of web development and APIs, there are several types of
requests that clients can make to servers to interact with resources.
These requests are typically categorized based on the HTTP method
used for making the request. The most common HTTP methods used for
making requests are:
• GET:
• The GET method is used to request data from a specified
resource.
• It is used to retrieve data or information from the server
without modifying it.
• GET requests should only be used for idempotent
operations, meaning that they should not have any side
effects on the server.
• Example: Retrieving a list of products from an e-commerce
website.
• POST:
• The POST method is used to submit data to be processed to
a specified resource.
• It is commonly used for creating new resources or submitting
form data to the server.
• POST requests can have side effects on the server, such as
creating or updating data.
• Example: Submitting a new order to an e-commerce website.
• PUT:
• The PUT method is used to update data on a specified
resource.
• It is commonly used for updating existing resources with new
data.
• PUT requests are idempotent, meaning that multiple identical
requests should have the same effect as a single request.
• Example: Updating the details of a user profile.
• DELETE:
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
164 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
These are the most commonly used HTTP methods for making requests
to web servers. Each method has its specific purpose and usage, and
understanding their differences is essential for building RESTful APIs
and interacting with web resources effectively.
RETROFIT
Retrofit is a type-safe HTTP client for Android and Java that simplifies
the process of consuming RESTful web services. It is a widely used
library for making network requests and handling API responses in
Android apps. Retrofit is developed by Square, the same company
behind other popular libraries such as OkHttp.
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
165 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
• Declarative API:
• Retrofit provides a high-level, declarative API for defining
HTTP requests and handling responses.
• It allows developers to define interfaces that represent
RESTful API endpoints, with methods corresponding to
different HTTP operations (GET, POST, PUT, DELETE, etc.)
and annotations for specifying request parameters, headers,
and response types.
• Type-Safe Requests:
• Retrofit generates implementation code for the defined
interfaces at compile time, providing type safety and
ensuring that requests and responses are properly handled.
• Developers can define Java interfaces with method
signatures that match the expected request and response
types, making the code more readable and maintainable.
• Integration with OkHttp:
• Retrofit seamlessly integrates with OkHttp, a powerful HTTP
client library for Java and Android, for handling network
communication.
• OkHttp provides features such as connection pooling,
request/response caching, and interceptors, which Retrofit
leverages to provide efficient and reliable network
communication.
• Serialization and Deserialization:
• Retrofit supports automatic serialization of request bodies
and deserialization of response bodies using converter
libraries such as Gson, Moshi, Jackson, and XML.
• Developers can configure Retrofit to use their preferred
serialization/deserialization library based on the data format
(JSON, XML) used by the API.
• Asynchronous and Synchronous Execution:
• Retrofit supports both synchronous and asynchronous
execution of HTTP requests.
• Asynchronous requests are executed on background
threads, allowing the main UI thread to remain responsive,
while synchronous requests are executed on the calling
thread, potentially blocking it until the request completes.
• Error Handling:
API:
API:
Registration
URL: https://androindian.com/test/Register.php
Request:
{“username”:“Raj”,“password”:“1234”,“email”:“Rajtest2356178@admin}
Response:
{“key”:”You are registered successfully.”,”status”:”success”}
{“key”:”Email already Exists”,”status”:”failed”}
API:
URL: https://androindian.com/test/Register.php
Request:
{“username”:“[email protected]”,“password”:“1234”}
Response:
{“key”:”Login successfully.”,”status”:”success”}
{“key”:”invalid credentials”,”status”:”failed”}
Build .gradle
plugins {
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
167 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
id("com.android.application")
id("org.jetbrains.kotlin.android")
}
android {
namespace = "com.example.project8pm"
compileSdk = 34
defaultConfig {
applicationId = "com.example.project8pm"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner =
"androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
dataBinding{
enable=true
}
}
dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-
core:3.5.1")
implementation ("com.squareup.retrofit2:converter-gson:2.4.0")
implementation ("com.squareup.retrofit2:retrofit:2.4.0")
implementation ("com.google.code.gson:gson:2.8.9")
implementation ("com.squareup.picasso:picasso:2.5.2")
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<layout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register Here"
android:layout_gravity="center" />
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
169 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="UserName"
android:layout_margin="5dp"
style="@style/Widget.MaterialComponents.TextInputLayout.Outli
nedBox">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="email"
android:layout_margin="5dp"
style="@style/Widget.MaterialComponents.TextInputLayout.Outli
nedBox">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:layout_margin="5dp"
style="@style/Widget.MaterialComponents.TextInputLayout.Outli
nedBox">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
170 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:padding="5dp"
android:layout_margin="5dp"
android:layout_gravity="center"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
</layout>
MainActivity.kt
package com.example.project8pm
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import com.example.project8pm.databinding.ActivityMainBinding
import com.google.gson.JsonParser
import org.json.JSONObject
import retrofit2.Call
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
binding?.login?.setOnClickListener {
var uname=binding?.username?.editText?.text.toString().trim()
var uemail=binding?.email?.editText?.text.toString().trim()
var upass=binding?.password?.editText?.text.toString().trim()
var jsonObject=JSONObject()
jsonObject.put("username",uname)
jsonObject.put("email",uemail)
jsonObject.put("password",upass)
var retrofit=Retrofit.Builder().
baseUrl("https://androindian.com/test/").
addConverterFactory(GsonConverterFactory.create()).build()
var retroInterface=retrofit.create(SampleInterface::class.java)
var requestjson=
JsonParser().parse(jsonObject.toString()).asJsonObject
var regresponsecall=retroInterface.createUser(requestjson)
regresponsecall?.enqueue(object :
retrofit2.Callback<RegisterResponse>{
override fun onResponse(
call: Call<RegisterResponse>,
response: Response<RegisterResponse>
){
var res=response.body()?.status
if(res.equals("success")){
var res1=response.body()?.key
Toast.makeText(this@MainActivity,res1,Toast.LENGTH_L
ONG).show()
var intent= Intent(this@MainActivity,Login::class.java)
startActivity(intent)
}else{
var res1=response.body()?.key
Toast.makeText(this@MainActivity,res1,Toast.LENGTH_L
ONG).show()
}
}
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
172 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
}
}
}
SampleInterface.kt
package com.example.project8pm
import com.google.gson.JsonObject
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Headers
import retrofit2.http.POST
@Headers("Content-Type:application/json")
@POST("Register_raw.php")
fun createUser(@Body jsonObject: JsonObject):
Call<RegisterResponse>
@Headers("Content-Type:application/json")
@POST("Login_raw.php")
fun loginUser(@Body jsonObject: JsonObject): Call<LoginResponse>
@Headers("Content-Type:application/json")
@GET("users?page=2")
fun loadData(): Call<ListResponse>
}
RegisterResponse.kt
package com.example.project8pm
import com.google.gson.annotations.Expose
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
173 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
import com.google.gson.annotations.SerializedName
class RegisterResponse {
@SerializedName("key")
@Expose
var key: String? = null
@SerializedName("status")
@Expose
var status: String? = null
}
Activity_login.xml
<?xml version="1.0" encoding="utf-8"?>
<layout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Login">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login Here"
android:layout_gravity="center" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/email"
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
174 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="email"
android:layout_margin="5dp"
style="@style/Widget.MaterialComponents.TextInputLayout.
OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:layout_margin="5dp"
style="@style/Widget.MaterialComponents.TextInputLayout.
OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:padding="5dp"
android:layout_margin="5dp"
android:layout_gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/newuser"
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
175 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
</LinearLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
</layout>
Login.kt
package com.example.project8pm
import android.content.Intent
import android.content.SharedPreferences
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import com.example.project8pm.databinding.ActivityLoginBinding
import com.google.gson.JsonParser
import org.json.JSONObject
import retrofit2.Call
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
binding?.newuser?.setOnClickListener {
var intent= Intent(this@Login,MainActivity::class.java)
startActivity(intent)
}
binding?.login?.setOnClickListener {
var uemail=binding?.email?.editText?.text.toString().trim()
var upass=binding?.password?.editText?.text.toString().trim()
jsonObject.put("username",uemail)
jsonObject.put("password",upass)
var retroInterface=retrofit.create(SampleInterface::class.java)
var requestjson=
JsonParser().parse(jsonObject.toString()).asJsonObject
var logsponsecall=retroInterface.loginUser(requestjson)
logsponsecall?.enqueue(object :
retrofit2.Callback<LoginResponse>{
override fun onResponse(
call: Call<LoginResponse>,
response: Response<LoginResponse>
){
var res=response.body()?.status
if(res.equals("success")){
var res1=response.body()?.key
Toast.makeText(this@Login,res1,
Toast.LENGTH_LONG).show()
var intent=Intent(this@Login,DashBoard::class.java)
startActivity(intent)
var
sharedpredpreferences=getSharedPreferences("Login",
MODE_PRIVATE)
var editor=sharedpredpreferences.edit()
// editor.put("key","vales")
editor.putString("email",uemail)
editor.putString("password",upass)
editor.commit()
}else{
var res1=response.body()?.key
Toast.makeText(this@Login,res1,
Toast.LENGTH_LONG).show()
}
}
}
}
}
LoginResponse.kt
package com.example.project8pm
import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName
class LoginResponse {
@SerializedName("key")
@Expose
var key: String? = null
@SerializedName("status")
@Expose
var status: String? = null
}
Activity_dashboard.xml
<?xml version="1.0" encoding="utf-8"?>
<layout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DashBoard"
android:orientation="vertical">
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
178 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/logout"
android:layout_margin="10dp"
android:text="Logout"/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:id="@+id/rec"/>
</LinearLayout>
</layout>
Dashboard.kt
package com.example.project8pm
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.project8pm.databinding.ActivityDashBoardBinding
import retrofit2.Call
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
var sharedpredpreferences=getSharedPreferences("Login",
MODE_PRIVATE)
var s1=sharedpredpreferences.getString("email",null)
var s2=sharedpredpreferences.getString("password",null)
Toast.makeText(this@DashBoard,s1+s2,Toast.LENGTH_LONG).sh
ow()
binding?.logout?.setOnClickListener {
var editor=sharedpredpreferences.edit()
editor.clear()
editor.apply()
}
connectionChecking=ConnectionChecking()
if(connectionChecking?.isConnectingToInternet(this@DashBoard)
== true) {
if (res !== 0) {
var linearLayoutManager =
LinearLayoutManager(this@DashBoard,
LinearLayoutManager.VERTICAL, false)
binding?.rec?.layoutManager = linearLayoutManager
var customAdapter = CustomAdapter(
this@DashBoard,
response.body()?.data as List<ListInsideData>
)
binding?.rec?.adapter = customAdapter
} else {
import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName
class ListResponse {
@SerializedName("page")
@Expose
var page: Int? = null
@SerializedName("per_page")
@Expose
var perPage: Int? = null
@SerializedName("total")
@Expose
var total: Int? = null
@SerializedName("total_pages")
@Expose
var totalPages: Int? = null
@SerializedName("data")
@Expose
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
181 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
@SerializedName("support")
@Expose
var support: Support? = null
}
ListInsideData.kt
package com.example.project8pm
import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName
class ListInsideData {
@SerializedName("id")
@Expose
var id: Int? = null
@SerializedName("email")
@Expose
var email: String? = null
@SerializedName("first_name")
@Expose
var firstName: String? = null
@SerializedName("last_name")
@Expose
var lastName: String? = null
@SerializedName("avatar")
@Expose
var avatar: String? = null
}
Support.kt
package com.example.project8pm
import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName
class Support {
@SerializedName("url")
@Expose
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
182 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
@SerializedName("text")
@Expose
var text: String? = null
}
CustomAdapter.kt
package com.example.project8pm
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.squareup.picasso.Picasso
init {
adpfname=itemView.findViewById(R.id.firstname)
adpemail=itemView.findViewById(R.id.email)
adpid=itemView.findViewById(R.id.uid)
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
183 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
adplname=itemView.findViewById(R.id.lastname)
adpimage=itemView.findViewById(R.id.profile)
}
Picasso.with(adpContext).load(adpdata.get(holder.adapterPosition).
avatar).into(holder.adpimage)
}
Custom.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.cardview.widget.CardView
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
184 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/profile"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/uid"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/firstname"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/lastname"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/email"/>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
Activity_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<layout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
185 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Splash">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/iv"
android:src="@mipmap/ic_launcher"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
</layout>
Splash.kt
package com.example.project8pm
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import androidx.databinding.DataBindingUtil
import com.example.project8pm.databinding.ActivitySplashBinding
animation=AnimationUtils.loadAnimation(this@Splash,R.anim.rotate
)
binding?.iv?.startAnimation(animation)
var sharedpredpreferences=getSharedPreferences("Login",
MODE_PRIVATE)
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
186 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
var s1=sharedpredpreferences.getString("email",null)
var s2=sharedpredpreferences.getString("password",null)
Handler().postDelayed(Runnable {
if(s1.isNullOrBlank()) {
var intent = Intent(this@Splash, Login::class.java)
startActivity(intent)
}else{
}
}
ConnectionChecking.kt
package com.example.project8pm
import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkInfo
class ConnectionChecking {
var
connectivity=context.getSystemService(Context.CONNECTIVITY_SERV
ICE) as ConnectivityManager
if(connectivity!=null){
var info=connectivity.allNetworkInfo
if(info!=null)
for (i in info.indices)
if(info[i].state== NetworkInfo.State.CONNECTED){
return true
}
}
return false
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
187 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Project8PM"
tools:targetApi="31">
<activity
android:name=".Login"
android:exported="false" />
<activity
android:name=".DashBoard"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="false" />
<activity
android:name=".Splash"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
188 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
</manifest>
VOLLEY
Volley is an HTTP library developed by Google that simplifies network
requests in Android applications. It provides a straightforward API for
making network requests, handling responses, and performing image
loading. Volley is designed to be fast, efficient, and easy to use, making
it a popular choice for networking tasks in Android apps.
Here are some key features of Volley:
• Ease of Use:
• Volley provides a simple and intuitive API for making network
requests, requiring minimal boilerplate code.
• It offers a RequestQueue class for managing and
dispatching network requests, making it easy to send
multiple requests simultaneously.
• Asynchronous Requests:
• Volley performs network requests asynchronously by default,
allowing the main UI thread to remain responsive.
• It automatically manages threading and concurrency,
handling network operations on background threads and
delivering results on the main thread.
• Request Prioritization and Cancellation:
• Volley allows developers to prioritize network requests based
on their importance or urgency.
• It supports request cancellation, allowing developers to
cancel ongoing requests if they are no longer needed or if
the user navigates away from the current screen.
• Automatic Retries and Backoff:
• Volley includes built-in support for automatic retries and
backoff strategies for handling transient network errors.
• It automatically retries failed requests with exponential
backoff, reducing the likelihood of server overload and
improving the reliability of network operations.
• Request Caching:
• Volley supports request caching, allowing responses to be
cached on the device to improve performance and reduce
network usage.
• It provides a flexible caching mechanism that can be
customized based on the requirements of the application.
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
189 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
• Image Loading:
• Volley includes a specialized module for loading images from
network URLs and caching them in memory and/or disk.
• It provides efficient handling of image requests, including
automatic resizing, caching, and memory management.
• Customizable Retry Policies and Timeouts:
• Volley allows developers to customize retry policies and
timeouts for individual requests or for the entire
RequestQueue.
• It provides fine-grained control over network behavior,
allowing developers to optimize performance and reliability
based on specific requirements.
• Integration with Android:
• Volley is designed to integrate seamlessly with Android
applications and follows Android best practices and
conventions.
• It supports features such as asynchronous loading of images
into ImageViews, request prioritization, and automatic
request cancellation in response to activity lifecycle events.
Example program
Build.gardle
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
}
android {
namespace = "com.example.volleyexreg"
compileSdk = 34
defaultConfig {
applicationId = "com.example.volleyexreg"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
190 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
testInstrumentationRunner =
"androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
dataBinding{
enable=true
}
}
dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-
core:3.5.1")
implementation ("com.android.volley:volley:1.2.1")
}
Activity_main.xml
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:id="@+id/name"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:id="@+id/email"/> <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Pass"
android:id="@+id/Pass"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Reg"
android:id="@+id/Reg"/>
</LinearLayout>
</layout>
MainActivity.kt
package com.example.volleyexreg
import android.os.Bundle
import android.widget.Toast
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
192 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.android.volley.Request
import com.android.volley.RequestQueue
import com.android.volley.toolbox.JsonObjectRequest
import com.android.volley.toolbox.Volley
import com.example.volleyexreg.databinding.ActivityMainBinding
import org.json.JSONException
import org.json.JSONObject
var url="https://androindian.com/test/Register_raw.php"
binding?.Reg?.setOnClickListener{
var jsonObject= JSONObject()
// jsonObject.put("key","Values")
jsonObject.put("username",binding?.name?.text.toString().trim())
jsonObject.put("password",binding?.Pass?.text.toString().trim())
jsonObject.put("email",binding?.email?.text.toString().trim())
var jsonObjectRequest=
JsonObjectRequest(Request.Method.POST,
url,jsonObject, { response->
var res=response.getString("status")
if(res.equals("failed", ignoreCase=true)){
var res1=response.getString("key")
Toast.makeText(this@MainActivity,res1,
Toast.LENGTH_LONG).show()
}else{
var res1=response.getString("key")
Toast.makeText(this@MainActivity,res1,
Toast.LENGTH_LONG).show()
}){
error->
Toast.makeText(this@MainActivity,""+error.toString(),
Toast.LENGTH_LONG).show()
}
requestQueue?.add(jsonObjectRequest)
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:usesCleartextTraffic="true"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Volleyexreg"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
194 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
</manifest>
FRAGMENTS
Fragments are a fundamental building block of Android user interfaces
that represent a portion of a user interface or behavior within an Activity.
They were introduced in Android 3.0 (API level 11) as a way to create
more modular and flexible UI designs, especially for larger screen sizes
such as tablets.
Here's an overview of fragments and their key features:
• Modular UI Components:
• Fragments represent reusable portions of a UI that can be
combined and reconfigured within an Activity.
• They allow developers to break down the user interface into
smaller, self-contained components, making it easier to
manage and maintain complex UIs.
• Lifecycle:
• Fragments have their own lifecycle, similar to Activities, with
methods such as onCreate(), onStart(), onResume(),
onPause(), onStop(), and onDestroy().
• They are tightly coupled with the lifecycle of their hosting
Activity and can receive lifecycle callbacks from the Activity.
• UI Components:
• Fragments can contain their own layout and UI components,
including views, buttons, text fields, etc.
• They can inflate layouts using XML resources or
programmatically create UI elements.
• Reusability:
• Fragments are designed to be reusable across multiple
Activities and layouts.
Overall, fragments are a powerful and flexible tool for building Android
user interfaces. They provide a modular and reusable way to create UI
components, facilitate communication between UI elements, and support
dynamic UI updates for a variety of screen sizes and configurations.
Fragment example
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<layout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
196 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fragment Example"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Load Fragment 1"
android:id="@+id/bt1"
android:layout_margin="10dp"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Load Fragment 2"
android:id="@+id/bt2"
android:layout_margin="10dp"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:id="@+id/frame"
android:background="#098"/>
</LinearLayout>
</layout>
MainActivity.kt
package com.example.fragmentex
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import com.example.fragmentex.databinding.ActivityMainBinding
binding?.bt1?.setOnClickListener{
var fragmentManager=supportFragmentManager
var fragmentTransaction=fragmentManager.beginTransaction()
var firstfrag=FirstFrag()
fragmentTransaction.replace(R.id.frame,firstfrag)
fragmentTransaction.commit()
}
binding?.bt2?.setOnClickListener{
var fragmentManager=supportFragmentManager
var fragmentTransaction=fragmentManager.beginTransaction()
var secfrag=SecFrag()
fragmentTransaction.replace(R.id.frame,secfrag)
fragmentTransaction.commit()
}
}
}
Fragment_first.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".FirstFrag">
</FrameLayout>
FirstFrag.kt
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
198 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
package com.example.fragmentex
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
/**
* A simple [Fragment] subclass.
* Use the [FirstFrag.newInstance] factory method to
* create an instance of this fragment.
*/
class FirstFrag : Fragment() {
// TODO: Rename and change types of parameters
private var param1: String? = null
private var param2: String? = null
companion object {
/**
* Use this factory method to create a new instance of
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
199 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bt3"
android:text="Move to Activity"/>
</LinearLayout>
</layout>
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
200 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
Secondfrag.kt
package com.example.fragmentex
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.databinding.DataBindingUtil
import com.example.fragmentex.databinding.FragmentSecBinding
//bt=view.findViewById(R.id.bt3)
binding?.bt3?.setOnClickListener{
var intent= Intent(context,HomePage::class.java)
startActivity(intent)
}
//return view
return binding?.root
}
}
HomePage.kt
package com.example.fragmentex
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
</androidx.constraintlayout.widget.ConstraintLayout>
Androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Fragmentex"
tools:targetApi="31">
<activity
android:name=".HomePage"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
202 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
</manifest>
SQLITE DATABASES
SQLite is a popular choice for developers due to its simplicity, reliability,
and efficiency. Here are some key aspects:
Example program
Activity_main.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sqlite Example"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:id="@+id/name"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="location"
android:id="@+id/location"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="designantion"
android:id="@+id/designation"
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
204 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Save"
android:id="@+id/save"
/>
</LinearLayout>
</layout>
MainActivity.kt
package com.example.sqliteexa
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import com.example.sqliteexa.databinding.ActivityMainBinding
binding?.save?.setOnClickListener {
var username=binding?.name?.text.toString().trim()
var location=binding?.location?.text.toString().trim()
var designation=binding?.designation?.text.toString().trim()
var dbHandler=DbHandler(this@MainActivity)
dbHandler.insertUserDetails(username,location,designation)
Toast.makeText(this@MainActivity," Detals
saved",Toast.LENGTH_LONG).show()
}
}
}
Dbhandler.kt
package com.example.sqliteexa
import android.annotation.SuppressLint
import android.content.ContentValues
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
companion object{
private const val DB_NAME="userdb"
private const val DB_VERSION=1
private const val Table_Users="userdetails"
private const val KEY_ID="id"
private const val KEY_NAME="name"
private const val KEY_LOC="location"
private const val KEY_DES="designation"
}
override fun onCreate(db: SQLiteDatabase?) {
// var CREATE_TABLE= ("CREATE TABLE " + Table_Users + "( " +
KEY_ID + "INTEGER PRIMARY KEY AUTOINCREMENT, " +
// KEY_NAME + "TEXT, " + KEY_LOC + "TEXT, "+ KEY_DES +
"TEXT" + ")")
//db?.execSQL(CREATE_TABLE)
}
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
206 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
var newRowId=db.insert(Table_Users,null,contentValues)
@SuppressLint("Range")
fun GetUser(): ArrayList<HashMap<String,String>>{
var db=this.writableDatabase
var userlist=ArrayList<HashMap<String,String>>()
var query="SELECT name, location, designation FROM "+
Table_Users
var cursor=db.rawQuery(query,null)
while (cursor.moveToNext()){
var user=HashMap<String,String>()
user["name"]=cursor.getString(cursor.getColumnIndex(KEY_NAM
E))
user["location"]=cursor.getString(cursor.getColumnIndex(KEY_L
OC))
user["designation"]=cursor.getString(cursor.getColumnIndex(KEY
_DES))
userlist.add(user)
}
return userlist
}
var db=this.writableDatabase
db.delete(Table_Users, KEY_ID + " =?", arrayOf(userid.toString()))
db.close()
}
contentValues.put(KEY_LOC,location)
contentValues.put(KEY_DES,desingnation)
return db.update(Table_Users,contentValues,"$KEY_ID=?",
arrayOf(id.toString()))
@SuppressLint("Range")
fun GetUserByUserid(userid: Int):
ArrayList<HashMap<String,String>>{
var db=this.writableDatabase
var userlist=ArrayList<HashMap<String,String>>()
var query="SELECT name, location, designation FROM "+
Table_Users
var cursor=db.query(Table_Users, arrayOf(KEY_NAME, KEY_LOC,
KEY_DES),
KEY_ID + "=?",
arrayOf(userid.toString()),
null,
null,
null,
null
)
if (cursor.moveToNext()){
var user=HashMap<String,String>()
user["name"]=cursor.getString(cursor.getColumnIndex(KEY_NAM
E))
user["location"]=cursor.getString(cursor.getColumnIndex(KEY_L
OC))
user["designation"]=cursor.getString(cursor.getColumnIndex(KEY
_DES))
userlist.add(user)
}
return userlist
}
}
Activity_detail.xml
<?xml version="1.0" encoding="utf-8"?>
<layout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DetailActivity"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Saved Data"/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/list"/>
</LinearLayout>
</layout>
DetailActivity.kt
package com.example.sqliteexa
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ListAdapter
import android.widget.SimpleAdapter
import androidx.databinding.DataBindingUtil
import com.example.sqliteexa.databinding.ActivityDetailBinding
var dbHandler=DbHandler(this@DetailActivity)
var userlist=dbHandler.GetUser()
)
binding?.list?.adapter=simpleadapater
}
}
Custom,xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/name"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/location"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
210 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
android:id="@+id/designation"/>
</LinearLayout>
ROOMDATABASE
Room is an Android Library that provides an abstraction layer over
SQLite to allow for more robust database access while harnessing the
full power of SQLite. It simplifies database interactions and provides
compile-time checks, better performance, and increased readability of
code compared to using SQLite directly.
Here are some key features of Room:
Build.gradle
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.example.roomexample"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
212 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
// Room components
implementation 'androidx.room:room-runtime:2.4.0'
implementation 'androidx.room:room-ktx:2.4.0'
kapt 'androidx.room:room-compiler:2.4.0'
// Coroutine support
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
MainActivity.kt
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.room.Room
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
// Inserting a user
GlobalScope.launch(Dispatchers.IO) {
userDao.insertUser(User(name = "John", age = 30))
}
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Room Example"
android:textSize="24sp"
android:layout_centerInParent="true"/>
</RelativeLayout>
user.kt
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "users")
data class User(
@PrimaryKey(autoGenerate = true)
val id: Long = 0,
val name: String,
val age: Int
)
MyappDatabse.kt
import android.content.Context
import androidx.room.Database
import androidx.room.Room
companion object {
@Volatile
private var INSTANCE: MyAppDatabase? = null
• Material:
• Material is the metaphor used in Material Design. It's inspired
by the physical world and its textures, with elements like
paper and ink. Material surfaces reimagine the mediums of
paper and ink.
• Components:
• Material Design provides a comprehensive set of UI
components such as buttons, cards, text fields, dialogs, and
• Update Your App: Regularly update your app with bug fixes, new
features, and improvements based on user feedback and
analytics.
ADMOBACCOUNT
To add ads to your Android app, you typically integrate a third-party ad
network SDK into your app and then use their APIs to display ads.
Here's a general guide on how to do it using Google AdMob, one of the
most popular ad networks for Android apps:
1. SET UP GOOGLE ADMOB:
• Create an AdMob Account: Sign up for an account on the AdMob
website.
• Create an Ad Unit: Once logged in, create an ad unit for your app.
Choose the ad format (e.g., banner, interstitial, rewarded) and
specify the details.
implementation 'com.google.android.gms:play-services-ads:20.7.0'
Initialize AdMob: Initialize the AdMob SDK in your app's Application class or
in the onCreate() method of your main activity.
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
MobileAds.initialize(this)
}
}
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:adSize="BANNER"
app:adUnitId="@string/banner_ad_unit_id"/>
• Interstitial Ads: Interstitial ads are full-screen ads that cover the
interface of an app. You need to load and display them
programmatically at appropriate times (e.g., between game levels).
• Rewarded Ads: Rewarded ads are ads that users can choose to
watch in exchange for in-app rewards. You also need to load and
display them programmatically.
Interstitial Ads: Load and display interstitial ads when appropriate (e.g.,
after a game level).
Rewarded Ads: Load and display rewarded ads, and listen for events
such as user watching the ad.
val rewardedAd = RewardedAd(this,
getString(R.string.rewarded_ad_unit_id))
val adCallback = object : RewardedAdCallback() {
override fun onRewardedAdClosed() {
// Ad closed, proceed with reward if applicable
}
}
rewardedAd.fullScreenContentCallback = adCallback
rewardedAd.loadAd(AdRequest.Builder().build())
// Display the ad when ready
rewardedAd.show(this, adCallback)
That's a general overview of how to add ads to your Android app using
Google AdMob. Remember to follow AdMob's policies and guidelines to
ensure compliance and maximize ad revenue while providing a good
user experience.
GOOGLE MAPS
To display maps in your Android app using the Google Maps API, you
need to obtain an API key from the Google Cloud Console. Here's how
you can generate a Google Maps API key:
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
221 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
<application>
<!-- Other application elements -->
DURGASOFT, # 202, 2nd Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
222 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Android & Kotlin Study Material
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY" />
</application>
7. TESTING:
• Run your app on a physical device or emulator that has Google
Play services installed.
• If everything is set up correctly, you should be able to display
maps in your app using the Google Maps API.
That's it! You've successfully generated a Google Maps API key and
integrated it into your Android app. Now you can use the key to display
maps and utilize other features provided by the Google Maps API.
4. DOUBLE-CLICK ON "SIGNINGREPORT":
• Inside the "android" folder, you'll find a task named "signingReport". Double-
click on it.
EXAMPLE:
ruby
Variant: debug
Config: debug
Store: /path/to/your/debug.keystore
Alias: androiddebugkey
MD5: A1:B2:C3:D4:E5:F6:G7:H8:I9:J0:K1:L2:M3:N4:O5:P6
SHA1: A1B2C3D4E5F6G7H8I9J0K1L2M3N4O5P6
SHA-256: A1B2C3D4E5F6G7H8I9J0K1L2M3N4O5P6
Valid until: Wednesday, December 31, 2049
• Make sure you are using the correct keystore file (debug or
release) depending on whether you are building your app for
development or production.
• The SHA-1 key is required for configuring API keys for services
like Google Maps, Firebase, etc.
That's it! You've successfully generated the SHA-1 key for your app's
signing certificate in Android Studio. You can now use this key to
configure API access for various services.