Pro Android with Kotlin


Download 5.42 Mb.
Pdf ko'rish
bet39/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   35   36   37   38   39   40   41   42   ...   223
Bog'liq
@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.



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   35   36   37   38   39   40   41   42   ...   223




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling