Beruflich Dokumente
Kultur Dokumente
1. Intents
2. Alarm Managers & Job Schedulers
3. Content Providers
4. Notification Manager (Local Notifications & Push
Notifications)
5. Activity vs Fragments
6. Service
7. Broadcast Receiver
8. Contexts
Services
Used for:
1. Potentially long running tasks
2. Processing Big Data
3. Updating content providers
4. Backing up data.
5. Internet downloads
Types of Services:
1. Unbounded/ Started Service (Runs on main thread)
1. IntentService (Pre-Oreo) (Runs on background thread)
2. JobIntentService (Oreo+) (Runs on background thread)
2. Bounded Service (Runs on main thread)
Note: Service runs in the same process as the main thread of the application.
Note: You have 5 seconds to move this started service to foreground and attach
persistent notification, otherwise you will get ANR (Application not responding) error.
Note: A service is only started once, no matter how often you call the
startService() method. You need to stop ‘Started service’, otherwise it will keep on
running.
Handling
latest target
Version
https://github.com/shahwaiz90/Android-
Services/blob/master/app/src/main/java/io/smd/androidservices/S
tartedService.java
http://www.vogella.com/tutorials/AndroidServices/ar
ticle.html
Intent Service
1. Apps which are not targeting Oreo or Oreo+ can use IntentService as well.
3. Apps which are targeting Oreo or Oreo+ they must use JobIntentService.
Note: IntentService is a service, and is therefore subject to the new restrictions on background services. As a result, many apps that rely
on IntentService do not work properly when targeting Android 8.0 or higher. For this reason, Android Support Library 26.0.0 introduces a
new JobIntentService class, which provides the same functionality as IntentService but uses jobs instead of services when running on
Android 8.0 or higher.
https://developer.android.com/about/versions/oreo
/background
Job Intent Service
MainActivity
4. Bounded service will get terminated by Android OS when the last client has
unbound.
Local Binding:
Implementation by Ibinder
Remote Binding:
Implementation by Messeger and AIDL
(Multi Threading Environment – Could
get complicated).
All registered receivers for an event are notified by the Android runtime once
this event happens.
System Broadcasts:
Broadcast Listeners?!
Steps to register for Broadcast listener
1. Declare your listener (class name) in manifest.
3. Now create a separate class (Your broadcast Listener name which extends
from BroadcastReceiver)
To be continued in
next lecture!!!!
Tutorial Links
Home Exercise:
Try to run above git code and do experiments on it. It has
following 3 services integrated.
StartService, Bounded Service and JobIntentService