Pro Android with Kotlin



Yüklə 4,6 Kb.
Pdf görüntüsü
səhifə49/231
tarix29.11.2023
ölçüsü4,6 Kb.
#138831
1   ...   45   46   47   48   49   50   51   52   ...   231
@de android telegram Pro Android with Kotlin Developing Modern Mobile

40
CHAPTER 4: Services
onHandleIntent()
method. Since basically you don’t need anything else, 
the 
IntentService
service is easy to implement. Note that starting with 
Android 8.0 (API level 26), restrictions apply to background processes, 
so under appropriate circumstances, consider using 
JobIntentService
classes instead.
 
android.support.v4.app.JobIntentService
: This uses a 
JobScheduler
to enqueue service execution requests. Starting with Android 8.0 (API 
level 26), consider using this service base class for background services. 
To implement such a service, you basically have to create a subclass 
of 
JobIntentService
and override the method 
onHandleWork(intent: 
Intent): Unit
to contain the service’s workload.
Services Lifecycle
Having described various service characteristics in the preceding sections, the actual 
lifecycle of a service from a bird’s-view perspective is arguably easier than that of an activity. 
However, be careful of services being able to run in the background. Also, because services 
are more readily subject to stops forced by the Android OS, they may require special 
attention in correspondence with service clients.
In your service implementation, you can overwrite any the lifecycle callbacks listed here, for 
example, to log service invocation information while developing or debugging:
 
onCreate()
 
onStartCommand()
 
onBind()
 
onUnbind()
 
onRebind()
 
onDestroy()


41
CHAPTER 4: Services
Figure 
4-1
shows an overview of the lifecycle of a service
Figure 4-1.
 Service
lifecycle



Yüklə 4,6 Kb.

Dostları ilə paylaş:
1   ...   45   46   47   48   49   50   51   52   ...   231




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə