Pro Android with Kotlin



Yüklə 4,6 Kb.
Pdf görüntüsü
səhifə39/231
tarix29.11.2023
ölçüsü4,6 Kb.
#138831
1   ...   35   36   37   38   39   40   41   42   ...   231
@de android telegram Pro Android with Kotlin Developing Modern Mobile

29
CHAPTER 4: Services
Starting with Android 8.0 (API level 26), a couple of limitations hold if you are instantiating 
background services the old way, and a shift toward using the 
JobScheduler
methodology 
is recommended. Apps running on Android 8.0 or newer are considered to run in the 
background, if none of the following is true:
 
The app has a visible activity, currently active or paused.
 
The app has a foreground service, in other words, a service has called 
startForegound()
during its operation.
 
Another foreground app is connected to it, either by using one of its 
services or by using it as a content provider.
Once an Android 8.0 app starts its life as a background app or is switched to being a 
background app, it has a window of a couple of minutes before it is considered 
idle
. Once 
idle, the background services of an app get stopped. As an exception to this, a background 
app will go on a 
whitelist
and is allowed to execute background services if it handles tasks 
visible to the user. Examples include handling a “Firebase Cloud Messaging” message, 
receiving a broadcast such as an SMS or MMS message, executing a 
PendingIntent
from a notification (an intent to be executed by a different app with the originating app’s 
permission), or starting a 
VpnService
.
Most things that were formerly accomplished by executing background jobs as of
Android 8.0 are considered to be eligible to be handled by the JobScheduler API;
see Chapter 
8
for more information.
Declaring Services
Services get declared inside the app’s 
AndroidManifest.xml
file as follows:





android:name=".MyService"
android:enabled="true"
android:exported="true">



See Table 
4-1
 for the flags available.



Yüklə 4,6 Kb.

Dostları ilə paylaş:
1   ...   35   36   37   38   39   40   41   42   ...   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ə