SlideShare a Scribd company logo
1 of 8
Download to read offline
Android 8.0 Behavior Changes
As everyone knows, a lot of changes made after API level 26 for optimizing Android system’s
performance, the battery uses and other system-level problems which I am writing below:
1- Changes in Service.
2- Changes in Broadcast Reciever.
3- Changes in Push Notification
1-Changes in Broadcast Reciever:
So before understanding the changes in broadcast receiver let’s first understand two types of
broadcast receivers in Android.
Implicit BroadCast Reciever: BroadCast Reciever that is provided by Android system
like CONNECTIVITY_CHANGE, ACTION_BATTERY_LOW.
Explicit BroadCast Receiver: BroadCast Receiver which is created by the user by extending
Broadcast Receiver class is Explicit BroadCast Reciever.
Now next thing is that you can register Broadcast Receiver in Android using two ways first using
java code and second is in manifest.xml file. The difference is when you declare Broadcast
Receiver using java code then this will not be triggered when your app is closed but if you
declare in manifest.xml then this will be triggered even if your app is not running.
So after Oreo, you can not declare every implicit broadcast receiver in manifest.xml (Note: Not
every Broadcast Reciever but few of them you can declare) and Android gives you a list of the
implicit broadcast receiver which you can declare in manifest.xml even after Oreo. Besides that
list, you can not declare any implicit broadcast receiver in manifest.xml file.
Ex- ACTION_LOCKED_BOOT_COMPLETED, ACTION_BOOT_COMPLETED
Android allows these broadcast because they are sent only once when system boot and too
many apps need to receive this broadcast to schedule alarm, jobs and so forth.
List of implicit Broadcast Reciever allowed after oreo.
Reason: If you register an app to receive broadcast then the app’s receiver consumes resources
every time the broadcast is sent. If too many apps are registered to receive broadcast then this
can cause problems because every apps receiver consumes resources and it also impacts the
user experience.
2-Changes in Service:
The main changes after Oreo are that Background Service is not allowed, only foreground
service is allowed. First, let’s understand when services are considered as background service :
Case 1: When you start a service and put the app in the background and the user is not aware of
your service.
Case 2: Your app is in the background and you are starting a service, eg an alarm manager
which gives you a callback and you start a service.
In the above-mentioned cases, these services will be considered as background services. So if
you run a background service then Android will kill your service after a certain amount of time,
but remember if you are using your app means your app is in foreground then service will not be
killed.
Reason: After Oreo background service is not allowed because the developer’s start their
services and the work done by the service gets completed, but the service still keeps
running. This leads to degradation in device performance and drains the battery. As I have
mentioned above, there is no more background service after Oreo so you might think about the
alternatives for it. Below I have stated the alternatives:
(a)-Foreground Service: Foreground service is if the user is aware that the service is running
like displaying a notification attached to service for example in Ganna music application you will
always see a notification while a song is playing.
(b)-Job Service: Another alternative for the background service is to use Job service which is
similar to service but the difference is that it is not in your hands to start it. You will just create
your JobService object and give this to Job Scheduler and Job scheduler will start this service
when it will see that the resources are free. You can not force JobShedular to start your Job
Service immediately, but you can just request the Job Scheduler to start in some specific time
which is shown in the example below. JobShedular is similar to ThreadShedular and JobService
is similar to Thread. You can also define different event for starting your job service. For
example, the service will start when the device is connected to the internet or it is charging. You
can also call Job Service as a combination of BroadCast Reciever and Service.
Events that you can attach with your Job Service.
1
2
3
4
5
6
7
8
9
10
11
12
13
//ExampleJobService code
public class PracticeJobService extends JobService
{
@Override
public boolean onStartJob(JobParameters params)
{
//Start here your thread and do your task
return true;
}
@Override
public boolean onStopJob(JobParameters params) {
14
15
16
17
Log.d(TAG, "Your Job Stoped");
return true;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//MainActivity Code put this method in on create of your activiy.
public void scheduleJob()
{
ComponentName componentObject = new ComponentName(this, PracticeJobService .class);
JobInfo jobInfoObject = new JobInfo.Builder(101, componentObject )
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)//run when you connected to wifi
.setPersisted(false)//also alive if you rebot you phone
.setRequiresCharging(true) //Run when charging connect
.setPeriodic(10 * 60 * 1000) //Request JobShedular to start with in this time it just a request
JobShedular can also ignore this.
.build();
JobScheduler schedulerObject = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE);
int resultCodeValue = schedulerObject .schedule(jobInfoObject);
if (resultCodeValue == JobScheduler.RESULT_SUCCESS) {
Log.d(TAG, "Your Job scheduled");
} else {
Log.d(TAG, "Job scheduling failed");
}
}
public void cancelJob() {
JobScheduler jobSchedulerObject = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE);
jobSchedulerObject.cancel(101);
26 Log.d(TAG, "Your Job cancelled");
}
And now this will run even if your app is in the background.
Let’s understand some important things related to Service with the following points:
(I)- You start a Service with start service () method when your app is running means app is in
foreground then Service will not be killed in any case.
(II)- When you are starting your Service with startService() method then in onStartCommand
method of Service class, call startForground() method and give a notification object and now a
notification will show as long your Service will be running. As I have told you above after Oreo for
displaying a notification please create a channel for notification. I will suggest you create the
channel in the Application file of the project. The use of this notification channel is explained
below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
//Get some value pass by intent
String data= intent.getStringExtra("intentExtraInput");
//Intent object
Intent intentOject = new Intent(this, MainActivity.class);
//Pending Intent object
PendingIntent pendingIntentObject = PendingIntent.getActivity(this,
0, intentOject , 0);
//Notification Object
Notification myNotificationObject = new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("My Foregorund Service")
.setContentText(data)
.setSmallIcon(R.drawable.ic_android_icon)
.setContentIntent(pendingIntentObject)
.build();
//Start foreground method
19
20
21
22
startForeground(1, myNotificationObject);
//its for what happen with your when application is killed
return START_NOT_STICKY;
}
Now, this is your foreground Service but If you will not call startForeground() method from
onStartCommand() method and put your app in the background then after some Android will kill
your Service.
(III)-You can use not StartService() method when your app is in the background after Oreo if you
call this then Android will through IllegalStateException.
(IV)-If you are starting a Service when your app is in the background then use
startForegroundService() method, and one more thing after calling startService() Method Android
will give you 5 seconds to call startForeground() method from onStartCommand().If within 5
seconds you call this method then Android will continue your Service otherwise after 5 seconds it
will be killed.
Note: Always use ContextCompat class and it will handle conditions related to Android version.
ContextCompat.startForegroundService(this, serviceIntent);
1
2
3
4
5
6
7
8
9
10
11
public static void startForegroundService(@NonNull Context context, @NonNull Intent intent)
{
if (VERSION.SDK_INT < 26)
{
context.startService(intent);
}
else
{
context.startForegroundService(intent);
}
}
3-Changes in Notification:
After Oreo, you can divide your app’s notifications into channels. You can set different behavior
on different channels. All notifications that are posted to the same channel have the same
behavior. For example, I can create a channel for the most urgent notifications. By using the
channel, every notification will have a different sound, vibration or a notification light. You can
create more channels like this and can customize according to your requirements. So after Oreo,
you have more control over your notifications.
We have one more chance after Oreo which are notification dots. Now after Oreo if your
notifications appear then you will see dots or badges on app launcher icons. So for now if
you want to know for a particular application if you have gotten a new notification then you can
check the dots displayed along with the application’s icon. I will suggest you create notification
channel in Application class of project like given in the code below-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class MyApplication extends Application {
public static final String NOTIFICATION_CHANNEL_ID = "exampleServiceChannel";
@Override
public void onCreate() {
super.onCreate();
createChannelForPushNotification();
}
private void createChannelForPushNotification() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channelObject = new NotificationChannel(
NOTIFICATION_CHANNEL_ID,
"Example Service Channel",
NotificationManager.IMPORTANCE_DEFAULT
);
//set the light for notification
channelObject.setLightColor(Color.RED);
//set the light with enable or not
channelObject.enableLights(true);
22
23
24
25
26
27
28
29
30
//Set vibration enable or not
channelObject.enableVibration(true);
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(channelObject);
}
}
}
Now your notification channel is created with channel id “exampleServiceChannel” , you will use
this channel id when you create you notification builder object like below:
1
2
3
4
5
6
Notification notificationObjet = new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("My Push Notificaion")
.setContentText(input)
.setSmallIcon(R.drawable.ic_android_icon)
.setContentIntent(pendingIntentObject)
.build();
Conclusion: I have tried to cover each and every point related to changes in Push Notification,
Service and BroadCast Reciever after Oreo. I hope the concepts are easy to grasp and in case
of any mistakes please feel free to comment below.
InnovationM is a globally renowned mobile app development company in India that caters a
robust & secure Android app development, iOS app development, hybrid app development
services. Our commitment & engagement towards our target gives us brighter in the world of
technology and has led us to establish success stories consecutively. InnovationM is the
top Android app development company in India.
Thanks for giving your valuable time. Keep reading and keep learning.
InnovationM Technology Solutions
A-36, Sector-4 Noida 201310
Sales@innovationm.com
https://www.innovationm.com/
+91 7838065578

More Related Content

Similar to Android 8 behavior changes

Android service, aidl - day 1
Android service, aidl - day 1Android service, aidl - day 1
Android service, aidl - day 1Utkarsh Mankad
 
Day 15: Working in Background
Day 15: Working in BackgroundDay 15: Working in Background
Day 15: Working in BackgroundAhsanul Karim
 
Android Training (Services)
Android Training (Services)Android Training (Services)
Android Training (Services)Khaled Anaqwa
 
Services I.pptx
Services I.pptxServices I.pptx
Services I.pptxRiziX3
 
android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semaswinbiju1652
 
Android broadcast receiver tutorial
Android broadcast receiver  tutorialAndroid broadcast receiver  tutorial
Android broadcast receiver tutorialmaamir farooq
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recieversUtkarsh Mankad
 
IBM MobileFirst Platform v7.0 POT App Mgmt Lab v1.1
IBM MobileFirst Platform  v7.0 POT App Mgmt Lab v1.1IBM MobileFirst Platform  v7.0 POT App Mgmt Lab v1.1
IBM MobileFirst Platform v7.0 POT App Mgmt Lab v1.1Banking at Ho Chi Minh city
 
How to implement Micro-frontends using Qiankun
How to implement Micro-frontends using QiankunHow to implement Micro-frontends using Qiankun
How to implement Micro-frontends using QiankunFibonalabs
 
Android scheduling.pptx
Android scheduling.pptxAndroid scheduling.pptx
Android scheduling.pptxZakiKhan66
 
Delphi - Howto Services
Delphi - Howto ServicesDelphi - Howto Services
Delphi - Howto ServicesNiall Munro
 
Manual testing interview questions
Manual testing interview questionsManual testing interview questions
Manual testing interview questionsBABAR MANZAR
 

Similar to Android 8 behavior changes (20)

Android service, aidl - day 1
Android service, aidl - day 1Android service, aidl - day 1
Android service, aidl - day 1
 
Gaad01 job scheduler
Gaad01 job schedulerGaad01 job scheduler
Gaad01 job scheduler
 
Day 15: Working in Background
Day 15: Working in BackgroundDay 15: Working in Background
Day 15: Working in Background
 
Android Training (Services)
Android Training (Services)Android Training (Services)
Android Training (Services)
 
Services I.pptx
Services I.pptxServices I.pptx
Services I.pptx
 
android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last sem
 
Android broadcast receiver tutorial
Android broadcast receiver  tutorialAndroid broadcast receiver  tutorial
Android broadcast receiver tutorial
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Unit2
Unit2Unit2
Unit2
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recievers
 
IBM MobileFirst Platform v7.0 POT App Mgmt Lab v1.1
IBM MobileFirst Platform  v7.0 POT App Mgmt Lab v1.1IBM MobileFirst Platform  v7.0 POT App Mgmt Lab v1.1
IBM MobileFirst Platform v7.0 POT App Mgmt Lab v1.1
 
Android Services
Android ServicesAndroid Services
Android Services
 
How to implement Micro-frontends using Qiankun
How to implement Micro-frontends using QiankunHow to implement Micro-frontends using Qiankun
How to implement Micro-frontends using Qiankun
 
Android scheduling.pptx
Android scheduling.pptxAndroid scheduling.pptx
Android scheduling.pptx
 
Ppt 2 android_basics
Ppt 2 android_basicsPpt 2 android_basics
Ppt 2 android_basics
 
Delphi - Howto Services
Delphi - Howto ServicesDelphi - Howto Services
Delphi - Howto Services
 
Manual testing interview questions
Manual testing interview questionsManual testing interview questions
Manual testing interview questions
 

More from InnovationM

How to use data binding in android
How to use data binding in androidHow to use data binding in android
How to use data binding in androidInnovationM
 
Capture image on eye blink
Capture image on eye blinkCapture image on eye blink
Capture image on eye blinkInnovationM
 
How to use geolocation in react native apps
How to use geolocation in react native appsHow to use geolocation in react native apps
How to use geolocation in react native appsInnovationM
 
Understanding of react fiber architecture
Understanding of react fiber architectureUnderstanding of react fiber architecture
Understanding of react fiber architectureInnovationM
 
Automatic reference counting (arc) and memory management in swift
Automatic reference counting (arc) and memory management in swiftAutomatic reference counting (arc) and memory management in swift
Automatic reference counting (arc) and memory management in swiftInnovationM
 
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...InnovationM
 
How prototype works in java script?
How prototype works in java script?How prototype works in java script?
How prototype works in java script?InnovationM
 
React – Let’s “Hook” up
React – Let’s “Hook” upReact – Let’s “Hook” up
React – Let’s “Hook” upInnovationM
 
Razorpay Payment Gateway Integration In iOS Swift
Razorpay Payment Gateway Integration In iOS SwiftRazorpay Payment Gateway Integration In iOS Swift
Razorpay Payment Gateway Integration In iOS SwiftInnovationM
 
Paytm integration in swift
Paytm integration in swiftPaytm integration in swift
Paytm integration in swiftInnovationM
 
Line Messaging API Integration with Spring-Boot
Line Messaging API Integration with Spring-BootLine Messaging API Integration with Spring-Boot
Line Messaging API Integration with Spring-BootInnovationM
 
Basic fundamental of ReactJS
Basic fundamental of ReactJSBasic fundamental of ReactJS
Basic fundamental of ReactJSInnovationM
 
Basic Fundamental of Redux
Basic Fundamental of ReduxBasic Fundamental of Redux
Basic Fundamental of ReduxInnovationM
 
Integration of Highcharts with React ( JavaScript library )
Integration of Highcharts with React ( JavaScript library )Integration of Highcharts with React ( JavaScript library )
Integration of Highcharts with React ( JavaScript library )InnovationM
 
Serialization & De-serialization in Java
Serialization & De-serialization in JavaSerialization & De-serialization in Java
Serialization & De-serialization in JavaInnovationM
 
Concept of Stream API Java 1.8
Concept of Stream API Java 1.8Concept of Stream API Java 1.8
Concept of Stream API Java 1.8InnovationM
 
How to Make Each Round of Testing Count?
How to Make Each Round of Testing Count?How to Make Each Round of Testing Count?
How to Make Each Round of Testing Count?InnovationM
 
Model View Presenter For Android
Model View Presenter For AndroidModel View Presenter For Android
Model View Presenter For AndroidInnovationM
 
Retrofit Library In Android
Retrofit Library In AndroidRetrofit Library In Android
Retrofit Library In AndroidInnovationM
 

More from InnovationM (20)

How to use data binding in android
How to use data binding in androidHow to use data binding in android
How to use data binding in android
 
Capture image on eye blink
Capture image on eye blinkCapture image on eye blink
Capture image on eye blink
 
Mob x in react
Mob x in reactMob x in react
Mob x in react
 
How to use geolocation in react native apps
How to use geolocation in react native appsHow to use geolocation in react native apps
How to use geolocation in react native apps
 
Understanding of react fiber architecture
Understanding of react fiber architectureUnderstanding of react fiber architecture
Understanding of react fiber architecture
 
Automatic reference counting (arc) and memory management in swift
Automatic reference counting (arc) and memory management in swiftAutomatic reference counting (arc) and memory management in swift
Automatic reference counting (arc) and memory management in swift
 
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...
 
How prototype works in java script?
How prototype works in java script?How prototype works in java script?
How prototype works in java script?
 
React – Let’s “Hook” up
React – Let’s “Hook” upReact – Let’s “Hook” up
React – Let’s “Hook” up
 
Razorpay Payment Gateway Integration In iOS Swift
Razorpay Payment Gateway Integration In iOS SwiftRazorpay Payment Gateway Integration In iOS Swift
Razorpay Payment Gateway Integration In iOS Swift
 
Paytm integration in swift
Paytm integration in swiftPaytm integration in swift
Paytm integration in swift
 
Line Messaging API Integration with Spring-Boot
Line Messaging API Integration with Spring-BootLine Messaging API Integration with Spring-Boot
Line Messaging API Integration with Spring-Boot
 
Basic fundamental of ReactJS
Basic fundamental of ReactJSBasic fundamental of ReactJS
Basic fundamental of ReactJS
 
Basic Fundamental of Redux
Basic Fundamental of ReduxBasic Fundamental of Redux
Basic Fundamental of Redux
 
Integration of Highcharts with React ( JavaScript library )
Integration of Highcharts with React ( JavaScript library )Integration of Highcharts with React ( JavaScript library )
Integration of Highcharts with React ( JavaScript library )
 
Serialization & De-serialization in Java
Serialization & De-serialization in JavaSerialization & De-serialization in Java
Serialization & De-serialization in Java
 
Concept of Stream API Java 1.8
Concept of Stream API Java 1.8Concept of Stream API Java 1.8
Concept of Stream API Java 1.8
 
How to Make Each Round of Testing Count?
How to Make Each Round of Testing Count?How to Make Each Round of Testing Count?
How to Make Each Round of Testing Count?
 
Model View Presenter For Android
Model View Presenter For AndroidModel View Presenter For Android
Model View Presenter For Android
 
Retrofit Library In Android
Retrofit Library In AndroidRetrofit Library In Android
Retrofit Library In Android
 

Recently uploaded

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 

Recently uploaded (20)

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 

Android 8 behavior changes

  • 1. Android 8.0 Behavior Changes As everyone knows, a lot of changes made after API level 26 for optimizing Android system’s performance, the battery uses and other system-level problems which I am writing below: 1- Changes in Service. 2- Changes in Broadcast Reciever. 3- Changes in Push Notification 1-Changes in Broadcast Reciever: So before understanding the changes in broadcast receiver let’s first understand two types of broadcast receivers in Android. Implicit BroadCast Reciever: BroadCast Reciever that is provided by Android system like CONNECTIVITY_CHANGE, ACTION_BATTERY_LOW. Explicit BroadCast Receiver: BroadCast Receiver which is created by the user by extending Broadcast Receiver class is Explicit BroadCast Reciever. Now next thing is that you can register Broadcast Receiver in Android using two ways first using java code and second is in manifest.xml file. The difference is when you declare Broadcast Receiver using java code then this will not be triggered when your app is closed but if you declare in manifest.xml then this will be triggered even if your app is not running. So after Oreo, you can not declare every implicit broadcast receiver in manifest.xml (Note: Not every Broadcast Reciever but few of them you can declare) and Android gives you a list of the implicit broadcast receiver which you can declare in manifest.xml even after Oreo. Besides that list, you can not declare any implicit broadcast receiver in manifest.xml file. Ex- ACTION_LOCKED_BOOT_COMPLETED, ACTION_BOOT_COMPLETED Android allows these broadcast because they are sent only once when system boot and too many apps need to receive this broadcast to schedule alarm, jobs and so forth. List of implicit Broadcast Reciever allowed after oreo. Reason: If you register an app to receive broadcast then the app’s receiver consumes resources every time the broadcast is sent. If too many apps are registered to receive broadcast then this can cause problems because every apps receiver consumes resources and it also impacts the user experience. 2-Changes in Service: The main changes after Oreo are that Background Service is not allowed, only foreground service is allowed. First, let’s understand when services are considered as background service : Case 1: When you start a service and put the app in the background and the user is not aware of your service. Case 2: Your app is in the background and you are starting a service, eg an alarm manager which gives you a callback and you start a service.
  • 2. In the above-mentioned cases, these services will be considered as background services. So if you run a background service then Android will kill your service after a certain amount of time, but remember if you are using your app means your app is in foreground then service will not be killed. Reason: After Oreo background service is not allowed because the developer’s start their services and the work done by the service gets completed, but the service still keeps running. This leads to degradation in device performance and drains the battery. As I have mentioned above, there is no more background service after Oreo so you might think about the alternatives for it. Below I have stated the alternatives: (a)-Foreground Service: Foreground service is if the user is aware that the service is running like displaying a notification attached to service for example in Ganna music application you will always see a notification while a song is playing. (b)-Job Service: Another alternative for the background service is to use Job service which is similar to service but the difference is that it is not in your hands to start it. You will just create your JobService object and give this to Job Scheduler and Job scheduler will start this service when it will see that the resources are free. You can not force JobShedular to start your Job Service immediately, but you can just request the Job Scheduler to start in some specific time which is shown in the example below. JobShedular is similar to ThreadShedular and JobService is similar to Thread. You can also define different event for starting your job service. For example, the service will start when the device is connected to the internet or it is charging. You can also call Job Service as a combination of BroadCast Reciever and Service. Events that you can attach with your Job Service. 1 2 3 4 5 6 7 8 9 10 11 12 13 //ExampleJobService code public class PracticeJobService extends JobService { @Override public boolean onStartJob(JobParameters params) { //Start here your thread and do your task return true; } @Override public boolean onStopJob(JobParameters params) {
  • 3. 14 15 16 17 Log.d(TAG, "Your Job Stoped"); return true; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 //MainActivity Code put this method in on create of your activiy. public void scheduleJob() { ComponentName componentObject = new ComponentName(this, PracticeJobService .class); JobInfo jobInfoObject = new JobInfo.Builder(101, componentObject ) .setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)//run when you connected to wifi .setPersisted(false)//also alive if you rebot you phone .setRequiresCharging(true) //Run when charging connect .setPeriodic(10 * 60 * 1000) //Request JobShedular to start with in this time it just a request JobShedular can also ignore this. .build(); JobScheduler schedulerObject = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE); int resultCodeValue = schedulerObject .schedule(jobInfoObject); if (resultCodeValue == JobScheduler.RESULT_SUCCESS) { Log.d(TAG, "Your Job scheduled"); } else { Log.d(TAG, "Job scheduling failed"); } } public void cancelJob() { JobScheduler jobSchedulerObject = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE); jobSchedulerObject.cancel(101);
  • 4. 26 Log.d(TAG, "Your Job cancelled"); } And now this will run even if your app is in the background. Let’s understand some important things related to Service with the following points: (I)- You start a Service with start service () method when your app is running means app is in foreground then Service will not be killed in any case. (II)- When you are starting your Service with startService() method then in onStartCommand method of Service class, call startForground() method and give a notification object and now a notification will show as long your Service will be running. As I have told you above after Oreo for displaying a notification please create a channel for notification. I will suggest you create the channel in the Application file of the project. The use of this notification channel is explained below. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 @Override public int onStartCommand(Intent intent, int flags, int startId) { //Get some value pass by intent String data= intent.getStringExtra("intentExtraInput"); //Intent object Intent intentOject = new Intent(this, MainActivity.class); //Pending Intent object PendingIntent pendingIntentObject = PendingIntent.getActivity(this, 0, intentOject , 0); //Notification Object Notification myNotificationObject = new NotificationCompat.Builder(this, CHANNEL_ID) .setContentTitle("My Foregorund Service") .setContentText(data) .setSmallIcon(R.drawable.ic_android_icon) .setContentIntent(pendingIntentObject) .build(); //Start foreground method
  • 5. 19 20 21 22 startForeground(1, myNotificationObject); //its for what happen with your when application is killed return START_NOT_STICKY; } Now, this is your foreground Service but If you will not call startForeground() method from onStartCommand() method and put your app in the background then after some Android will kill your Service. (III)-You can use not StartService() method when your app is in the background after Oreo if you call this then Android will through IllegalStateException. (IV)-If you are starting a Service when your app is in the background then use startForegroundService() method, and one more thing after calling startService() Method Android will give you 5 seconds to call startForeground() method from onStartCommand().If within 5 seconds you call this method then Android will continue your Service otherwise after 5 seconds it will be killed. Note: Always use ContextCompat class and it will handle conditions related to Android version. ContextCompat.startForegroundService(this, serviceIntent); 1 2 3 4 5 6 7 8 9 10 11 public static void startForegroundService(@NonNull Context context, @NonNull Intent intent) { if (VERSION.SDK_INT < 26) { context.startService(intent); } else { context.startForegroundService(intent); } } 3-Changes in Notification:
  • 6. After Oreo, you can divide your app’s notifications into channels. You can set different behavior on different channels. All notifications that are posted to the same channel have the same behavior. For example, I can create a channel for the most urgent notifications. By using the channel, every notification will have a different sound, vibration or a notification light. You can create more channels like this and can customize according to your requirements. So after Oreo, you have more control over your notifications. We have one more chance after Oreo which are notification dots. Now after Oreo if your notifications appear then you will see dots or badges on app launcher icons. So for now if you want to know for a particular application if you have gotten a new notification then you can check the dots displayed along with the application’s icon. I will suggest you create notification channel in Application class of project like given in the code below- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 public class MyApplication extends Application { public static final String NOTIFICATION_CHANNEL_ID = "exampleServiceChannel"; @Override public void onCreate() { super.onCreate(); createChannelForPushNotification(); } private void createChannelForPushNotification() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channelObject = new NotificationChannel( NOTIFICATION_CHANNEL_ID, "Example Service Channel", NotificationManager.IMPORTANCE_DEFAULT ); //set the light for notification channelObject.setLightColor(Color.RED); //set the light with enable or not channelObject.enableLights(true);
  • 7. 22 23 24 25 26 27 28 29 30 //Set vibration enable or not channelObject.enableVibration(true); NotificationManager manager = getSystemService(NotificationManager.class); manager.createNotificationChannel(channelObject); } } } Now your notification channel is created with channel id “exampleServiceChannel” , you will use this channel id when you create you notification builder object like below: 1 2 3 4 5 6 Notification notificationObjet = new NotificationCompat.Builder(this, CHANNEL_ID) .setContentTitle("My Push Notificaion") .setContentText(input) .setSmallIcon(R.drawable.ic_android_icon) .setContentIntent(pendingIntentObject) .build(); Conclusion: I have tried to cover each and every point related to changes in Push Notification, Service and BroadCast Reciever after Oreo. I hope the concepts are easy to grasp and in case of any mistakes please feel free to comment below. InnovationM is a globally renowned mobile app development company in India that caters a robust & secure Android app development, iOS app development, hybrid app development services. Our commitment & engagement towards our target gives us brighter in the world of technology and has led us to establish success stories consecutively. InnovationM is the top Android app development company in India. Thanks for giving your valuable time. Keep reading and keep learning.
  • 8. InnovationM Technology Solutions A-36, Sector-4 Noida 201310 Sales@innovationm.com https://www.innovationm.com/ +91 7838065578