{"id":325293,"date":"2021-06-22T15:00:29","date_gmt":"2021-06-22T15:00:29","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=325293"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=325293","title":{"rendered":"\u0411\u043e\u043b\u0435\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0431\u043e\u0440\u0430 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 Android"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8b9\/db8\/17a\/8b9db817a660207b7ff4cb960def986c.png\" width=\"780\" height=\"439\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0434\u043b\u044f Android <a href=\"https:\/\/developer.android.com\/kotlin\/flow\"><u>\u043f\u043e\u0442\u043e\u043a\u0438 Kotlin<\/u><\/a> \u043e\u0431\u044b\u0447\u043d\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435. \u041e\u0434\u043d\u0430\u043a\u043e, \u0441\u043e\u0431\u0438\u0440\u0430\u044f \u044d\u0442\u0438 \u043f\u043e\u0442\u043e\u043a\u0438 (flows) \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0431\u043e\u0442\u044b, \u0447\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e, \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b (\u043a\u0430\u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430, \u0442\u0430\u043a \u0438 \u043f\u0430\u043c\u044f\u0442\u0438) \u0438\u043b\u0438 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0443\u0442\u0435\u0447\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0432 \u0444\u043e\u043d\u043e\u0432\u044b\u0439 \u0440\u0435\u0436\u0438\u043c.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0432\u044b \u0443\u0437\u043d\u0430\u0435\u0442\u0435, \u043a\u0430\u043a API <code>Lifecycle.repeatOnLifecycle<\/code> \u0438 <code>Flow.flowWithLifecycle<\/code> \u0437\u0430\u0449\u0438\u0449\u0430\u044e\u0442 \u0432\u0430\u0441 \u043e\u0442 \u043f\u0443\u0441\u0442\u043e\u0439 \u0442\u0440\u0430\u0442\u044b \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u0438\u0445 \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430.<\/p>\n<p><strong>. &nbsp; &nbsp; &nbsp; . &nbsp; &nbsp; &nbsp; .<\/strong><\/p>\n<h3>\u041d\u0435\u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432<\/h3>\n<p><a href=\"https:\/\/developer.android.com\/kotlin\/coroutines\/coroutines-best-practices#coroutines-data-layer\"><u>\u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f<\/u><\/a> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c API Flow&lt;T&gt; \u0441 \u043d\u0438\u0436\u043d\u0438\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0434\u0435\u0442\u0430\u043b\u0435\u0439 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u043f\u043e\u0442\u043e\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0442\u0430\u043a\u0436\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0438\u0445.<\/p>\n<p>\u0425\u043e\u043b\u043e\u0434\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0439 <a href=\"https:\/\/kotlinlang.org\/docs\/channels.html\"><u>\u043a\u0430\u043d\u0430\u043b\u043e\u043c<\/u><\/a> \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0441 \u0431\u0443\u0444\u0435\u0440\u0430\u043c\u0438, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a <a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/kotlinx-coroutines-core\/kotlinx.coroutines.flow\/buffer.html\"><u>buffer<\/u><\/a>, <a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/kotlinx-coroutines-core\/kotlinx.coroutines.flow\/conflate.html\"><u>conflate<\/u><\/a>, <a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/kotlinx-coroutines-core\/kotlinx.coroutines.flow\/flow-on.html\"><u>flowOn<\/u><\/a> \u0438\u043b\u0438 <a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/kotlinx-coroutines-core\/kotlinx.coroutines.flow\/share-in.html\"><u>shareIn<\/u><\/a>, \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c<strong> <\/strong>\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u0437 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 API, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a <a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/kotlinx-coroutines-core\/kotlinx.coroutines\/launch.html\"><u>CoroutineScope.launch<\/u><\/a>, <a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/kotlinx-coroutines-core\/kotlinx.coroutines.flow\/launch-in.html\"><u>Flow&lt;T&gt;.launchIn<\/u><\/a> \u0438\u043b\u0438 <a href=\"https:\/\/developer.android.com\/reference\/kotlin\/androidx\/lifecycle\/LifecycleCoroutineScope\"><u>LifecycleCoroutineScope.launchWhenX<\/u><\/a>, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u0432, \u0435\u0441\u043b\u0438 \u0432\u044b \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u0442\u0435 Job, \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0432\u0448\u0438\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443, \u043a\u043e\u0433\u0434\u0430 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0432 \u0444\u043e\u043d. \u042d\u0442\u0438 API \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c, \u043f\u043e\u043a\u0430 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u044d\u043c\u0438\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 \u0431\u0443\u0444\u0435\u0440 \u0432 \u0444\u043e\u043d\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u0445\u043e\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u044b.<\/p>\n<blockquote>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u0425\u043e\u043b\u043e\u0434\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u2014 \u044d\u0442\u043e \u0442\u0438\u043f \u043f\u043e\u0442\u043e\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0431\u043b\u043e\u043a \u043a\u043e\u0434\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u0430.<\/p>\n<\/blockquote>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u044d\u0442\u043e\u0442 \u043f\u043e\u0442\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0434\u0430\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/kotlinx-coroutines-core\/kotlinx.coroutines.flow\/callback-flow.html\"><u>callbackFlow<\/u><\/a>:<\/p>\n<pre><code class=\"kotlin\">\/\/ Implementation of a cold flow backed by a Channel that sends Location updates fun FusedLocationProviderClient.locationFlow() = callbackFlow&lt;Location&gt; {     val callback = object : LocationCallback() {         override fun onLocationResult(result: LocationResult?) {             result ?: return             try { offer(result.lastLocation) } catch(e: Exception) {}         }     }     requestLocationUpdates(createLocationRequest(), callback, Looper.getMainLooper())         .addOnFailureListener { e -&gt;             close(e) \/\/ in case of exception, close the Flow         }     \/\/ clean up when Flow collection ends     awaitClose {         removeLocationUpdates(callback)     } }<\/code><\/pre>\n<blockquote>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u0412\u043d\u0443\u0442\u0440\u0438 <code>callbackFlow<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <a href=\"https:\/\/kotlinlang.org\/docs\/reference\/coroutines\/channels.html\"><u>\u043a\u0430\u043d\u0430\u043b<\/u><\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Queue_(abstract_data_type)\"><u>\u043e\u0447\u0435\u0440\u0435\u0434\u044c<\/u><\/a> \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0438 \u0438\u043c\u0435\u0435\u0442 \u0435\u043c\u043a\u043e\u0441\u0442\u044c \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 64 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430.<\/p>\n<\/blockquote>\n<p>\u0421\u0431\u043e\u0440 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043b\u044e\u0431\u043e\u0433\u043e \u0438\u0437 \u0432\u044b\u0448\u0435\u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044b\u0445 API \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 \u0438\u0445 \u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435! \u0421\u043c. \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"kotlin\">class LocationActivity : AppCompatActivity() {     override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)          \/\/ Collects from the flow when the View is at least STARTED and         \/\/ SUSPENDS the collection when the lifecycle is STOPPED.         \/\/ Collecting the flow cancels when the View is DESTROYED.         lifecycleScope.launchWhenStarted {             locationProvider.locationFlow().collect {                 \/\/ New location! Update the map             }          }         \/\/ Same issue with:         \/\/ - lifecycleScope.launch { \/* Collect from locationFlow() here *\/ }         \/\/ - locationProvider.locationFlow().onEach { \/* ... *\/ }.launchIn(lifecycleScope)     } }<\/code><\/pre>\n<p><code>lifecycleScope.launchWhenStarted<\/code> \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b. \u041d\u043e\u0432\u044b\u0435 \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f, \u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c <code>callbackFlow<\/code> \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 API <code>lifecycleScope.launch<\/code> \u0438\u043b\u0438 <code>launchIn<\/code> \u0435\u0449\u0435 \u0431\u043e\u043b\u0435\u0435 \u043e\u043f\u0430\u0441\u043d\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043e\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0444\u043e\u043d\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435! \u0427\u0442\u043e \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043e\u0442\u043a\u0430\u0437\u0443 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0441 \u044d\u0442\u0438\u043c\u0438 API, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u0441\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u0442 \u0432 \u0444\u043e\u043d\u043e\u0432\u044b\u0439 \u0440\u0435\u0436\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c <code>callbackFlow<\/code> \u0438 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0433\u043e, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0431\u0443\u0434\u0435\u0442 \u044d\u043c\u0438\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438 \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e:<\/p>\n<pre><code class=\"kotlin\">class LocationActivity : AppCompatActivity() {      \/\/ Coroutine listening for Locations     private var locationUpdatesJob: Job? = null      override fun onStart() {         super.onStart()         locationUpdatesJob = lifecycleScope.launch {             locationProvider.locationFlow().collect {                 \/\/ New location! Update the map             }          }     }      override fun onStop() {         \/\/ Stop collecting when the View goes to the background         locationUpdatesJob?.cancel()         super.onStop()     } }<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043d\u043e \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434, \u0434\u0440\u0443\u0437\u044c\u044f! \u0418 \u0435\u0441\u043b\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u0441\u0435\u043e\u0431\u0449\u0430\u044f \u0438\u0441\u0442\u0438\u043d\u0430 \u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u0445 Android, \u0442\u043e \u043e\u043d\u0430 \u0442\u0430\u043a\u043e\u0432\u0430, \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u0435 \u043b\u044e\u0431\u0438\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434. \u041e\u0434\u043d\u043e \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432 \u043e\u0442\u043a\u0430\u0437\u0430 \u043e\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043e\u0434\u0430 \u043c\u0435\u043d\u044c\u0448\u0435 \u0448\u0430\u043d\u0441\u043e\u0432 \u0441\u043e\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443!<\/p>\n<h3>Lifecycle.repeatOnLifecycle<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0440\u0438\u0448\u043b\u0438 \u043a \u0435\u0434\u0438\u043d\u043e\u043c\u0443 \u043c\u043d\u0435\u043d\u0438\u044e \u0438 \u0437\u043d\u0430\u0435\u043c, \u0433\u0434\u0435 \u043a\u0440\u043e\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u043d\u0430\u0441\u0442\u0430\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c 1) \u043f\u0440\u043e\u0441\u0442\u044b\u043c, 2) \u0434\u0440\u0443\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0438\u043b\u0438 \u043b\u0435\u0433\u043a\u0438\u043c \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u044f\/\u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f, \u0438, \u0447\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0432\u0430\u0436\u043d\u043e, 3) \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c! \u041e\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0434\u0435\u0442\u0430\u043b\u0435\u0439 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043f\u043e\u0442\u043e\u043a\u0430.<\/p>\n<p>\u0411\u0435\u0437 \u043b\u0438\u0448\u043d\u0438\u0445 \u0441\u043b\u043e\u0432, API, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u044d\u0442\u043e <code>Lifecycle.repeatOnLifecycle<\/code>, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0439 \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 <a href=\"https:\/\/developer.android.com\/jetpack\/androidx\/releases\/lifecycle\"><u>lifecycle-runtime-ktx<\/u><\/a>.<\/p>\n<blockquote>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u042d\u0442\u0438 API \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 <code>lifecycle:lifecycle-runtime-ktx:2.4.0-alpha01<\/code> \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0437\u0434\u043d\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438.<\/p>\n<\/blockquote>\n<p>\u0412\u0437\u0433\u043b\u044f\u043d\u0438\u0442\u0435 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"kotlin\">class LocationActivity : AppCompatActivity() {     override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)          \/\/ Create a new coroutine since repeatOnLifecycle is a suspend function         lifecycleScope.launch {             \/\/ The block passed to repeatOnLifecycle is executed when the lifecycle             \/\/ is at least STARTED and is cancelled when the lifecycle is STOPPED.             \/\/ It automatically restarts the block when the lifecycle is STARTED again.             lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {                 \/\/ Safely collect from locationFlow when the lifecycle is STARTED                 \/\/ and stops collection when the lifecycle is STOPPED                 locationProvider.locationFlow().collect {                     \/\/ New location! Update the map                 }             }         }     } }<\/code><\/pre>\n<p><code>repeatOnLifecycle<\/code> \u2014 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0430\u044f <a href=\"https:\/\/developer.android.com\/reference\/android\/arch\/lifecycle\/Lifecycle.State\"><u>Lifecycle.State<\/u><\/a> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043d\u043e\u0432\u043e\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0441 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u043c \u0435\u0439 \u0431\u043b\u043e\u043a\u043e\u043c, \u043a\u043e\u0433\u0434\u0430 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442 \u044d\u0442\u043e\u0433\u043e <code>state<\/code>, \u0438 \u043e\u0442\u043c\u0435\u043d\u044b \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0435\u0439 \u044d\u0442\u043e\u0442 \u0431\u043b\u043e\u043a, \u043a\u043e\u0433\u0434\u0430 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u043f\u0430\u0434\u0430\u0435\u0442 \u043d\u0438\u0436\u0435 <code>state<\/code>.<\/p>\n<p>\u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043a\u043e\u0434, \u0434\u043b\u044f \u043e\u0442\u043c\u0435\u043d\u044b \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u0430, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>repeatOnLifecycle<\/code>. \u041a\u0430\u043a \u0432\u044b \u043c\u043e\u0433\u043b\u0438 \u0434\u043e\u0433\u0430\u0434\u0430\u0442\u044c\u0441\u044f, \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 API \u0432 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 <code>onCreate<\/code> \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 <code>onViewCreated<\/code> \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f. \u0421\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0438\u0436\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<pre><code class=\"kotlin\">class LocationFragment: Fragment() {     override fun onViewCreated(view: View, savedInstanceState: Bundle?) {         \/\/ ...         viewLifecycleOwner.lifecycleScope.launch {             viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {                 locationProvider.locationFlow().collect {                     \/\/ New location! Update the map                 }             }         }     } }<\/code><\/pre>\n<p><strong>\u0412\u0430\u0436\u043d\u043e:<\/strong> \u0424\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b <em>\u0432\u0441\u0435\u0433\u0434\u0430 <\/em>\u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>viewLifecycleOwner<\/code> \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a <code>DialogFragments<\/code>, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u043d\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0431\u044b\u0442\u044c View. \u0414\u043b\u044f <code>DialogFragments<\/code> \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>lifecycleOwner<\/code>.<\/p>\n<blockquote>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u042d\u0442\u0438 API \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 <code>lifecycle:lifecycle-runtime-ktx:2.4.0-alpha01<\/code> \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0437\u0434\u043d\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438.<\/p>\n<\/blockquote>\n<p><strong>\u041a\u043e\u043f\u043d\u0435\u043c \u0433\u043b\u0443\u0431\u0436\u0435!<\/strong><\/p>\n<p><code>repeatOnLifecycle<\/code> \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0443\u044e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443, \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0431\u043b\u043e\u043a, \u043a\u043e\u0433\u0434\u0430 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0432 \u0442\u0430\u0440\u0433\u0435\u0442 <code>state<\/code> \u0438 \u0438\u0437 \u043d\u0435\u0433\u043e \u0432 \u043d\u043e\u0432\u0443\u044e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443, \u0438 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0443\u044e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443, \u043a\u043e\u0433\u0434\u0430 Lifecycle \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0435\u0442\u0441\u044f. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u0443\u043d\u043a\u0442 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u0435\u043d: \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <code>repeatOnLifecycle<\/code>, \u043d\u0435 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u0438\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d.<\/p>\n<pre><code class=\"kotlin\">class LocationActivity : AppCompatActivity() {     override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)          \/\/ Create a coroutine         lifecycleScope.launch {                          lifecycle.repeatOnLifecycle(Lifecycle.State.RESUMED) {                 \/\/ Repeat when the lifecycle is RESUMED, cancel when PAUSED             }              \/\/ `lifecycle` is DESTROYED when the coroutine resumes. repeatOnLifecycle             \/\/ suspends the execution of the coroutine until the lifecycle is DESTROYED.         }     } }<\/code><\/pre>\n<h3>\u0412\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0430<\/h3>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f\u0441\u044c \u043a \u043d\u0430\u0447\u0430\u043b\u0443, \u0441\u0431\u043e\u0440 <code>locationFlow<\/code> \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0437 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u043e\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>lifecycleScope.launch<\/code>, \u0431\u044b\u043b \u043e\u043f\u0430\u0441\u0435\u043d, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u043b\u0441\u044f, \u0434\u0430\u0436\u0435 \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0432 \u0444\u043e\u043d\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435.<\/p>\n<p><code>repeatOnLifecycle<\/code> \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0440\u0430\u0442\u0443 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0438 \u0441\u0431\u043e\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0441\u0431\u043e\u0440 \u043f\u043e\u0442\u043e\u043a\u0430, \u043a\u043e\u0433\u0434\u0430 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0432 \u0442\u0430\u0440\u0433\u0435\u0442-\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/177\/5ff\/724\/1775ff724a04b1f780ef2e836292aa94.png\" alt=\"\u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438 \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c API repeatOnLifecycle\" title=\"\u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438 \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c API repeatOnLifecycle\" width=\"1600\" height=\"1212\"><figcaption>\u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438 \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c API repeatOnLifecycle<\/figcaption><\/figure>\n<h3>Flow.flowWithLifecycle<\/h3>\n<p>\u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>Flow.flowWithLifecycle<\/code>, \u043a\u043e\u0433\u0434\u0430 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430. \u042d\u0442\u043e\u0442 API \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <code>repeatOnLifecycle<\/code>, \u044d\u043c\u0438\u0442\u0438\u0440\u0443\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438 \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f, \u043a\u043e\u0433\u0434\u0430 Lifecycle \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0432 \u0442\u0430\u0440\u0433\u0435\u0442-\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0438\u0437 \u043d\u0435\u0433\u043e.<\/p>\n<pre><code class=\"kotlin\">class LocationActivity : AppCompatActivity() {     override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)          \/\/ Listen to one flow in a lifecycle-aware manner using flowWithLifecycle         lifecycleScope.launch {             locationProvider.locationFlow()                 .flowWithLifecycle(this, Lifecycle.State.STARTED)                 .collect {                     \/\/ New location! Update the map                 }         }                  \/\/ Listen to multiple flows         lifecycleScope.launch {             lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {                 \/\/ As collect is a suspend function, if you want to collect                 \/\/ multiple flows in parallel, you need to do so in                  \/\/ different coroutines                 launch {                     flow1.collect { \/* Do something *\/ }                    }                                  launch {                     flow2.collect { \/* Do something *\/ }                 }             }         }     } }<\/code><\/pre>\n<blockquote>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>: \u042d\u0442\u043e API \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>Flow.flowOn(CoroutineContext)<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0435\u0446\u0435\u0434\u0435\u043d\u0442\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <code>Flow.flowWithLifecycle<\/code> \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 <code>CoroutineContext<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u0432\u043e\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430, \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044f \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u043f\u043e\u0442\u043e\u043a \u043d\u0435\u0437\u0430\u0442\u0440\u043e\u043d\u0443\u0442\u044b\u043c. \u0422\u0430\u043a\u0436\u0435, \u043f\u043e\u0434\u043e\u0431\u043d\u043e <code>flowOn<\/code>, <code>Flow.flowWithLifecycle<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0431\u0443\u0444\u0435\u0440 \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439, \u0435\u0441\u043b\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u044c \u043d\u0435 \u0443\u0441\u043f\u0435\u0432\u0430\u0435\u0442 \u0437\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u043c. \u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0435\u0433\u043e \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <code>callbackFlow<\/code>.<\/p>\n<\/blockquote>\n<h3>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430<\/h3>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u044d\u0442\u0438 API, \u043e\u0441\u0442\u0435\u0440\u0435\u0433\u0430\u0439\u0442\u0435\u0441\u044c <em>\u0433\u043e\u0440\u044f\u0447\u0438\u0445<\/em> \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u0445\u043e\u0442\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0442\u043e\u043a\u0438 \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442! \u0418\u043c\u0435\u0439\u0442\u0435 \u0432\u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u0434\u043b\u044f \u043d\u0438\u0445 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u0438 \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e, \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0439\u0442\u0435. \u041d\u0430\u043b\u0438\u0447\u0438\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u0432 \u0444\u043e\u043d\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043e\u043d \u0442\u0440\u0430\u0442\u0438\u0442 \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f: \u0432\u044b \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0435 \u0441\u0432\u0435\u0436\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0430 \u043d\u0435 <em>\u043d\u0430\u0432\u0435\u0440\u0441\u0442\u044b\u0432\u0430\u0435\u0442\u0435 \u0443\u043f\u0443\u0449\u0435\u043d\u043d\u043e\u0435<\/em> \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0435 \u043d\u0435\u0441\u0432\u0435\u0436\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u0440\u0435\u0448\u0438\u0442\u0435, \u0434\u043e\u043b\u0436\u0435\u043d \u043b\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u0431\u044b\u0442\u044c \u0432\u0441\u0435\u0433\u0434\u0430 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u0438\u043b\u0438 \u043d\u0435\u0442.<\/p>\n<p>API <code>MutableStateFlow<\/code> \u0438 <code>MutableSharedFlow<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043f\u043e\u043b\u0435 <code>subscriptionCount<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430, \u043a\u043e\u0433\u0434\u0430 <code>subscriptionCount<\/code> \u0440\u0430\u0432\u043d\u043e \u043d\u0443\u043b\u044e. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043e\u0431\u044a\u0435\u043a\u0442, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043f\u043e\u0442\u043e\u043a\u0430, \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>UiState<\/code>, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0439 \u0438\u0437 <code>ViewModel<\/code> \u0432 UI \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>StateFlow<\/code>. \u042d\u0442\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e! \u042d\u0442\u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0440\u0435\u0431\u0443\u0435\u0442, \u0447\u0442\u043e\u0431\u044b <code>ViewModel<\/code> \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u043b\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044e.<\/p>\n<p>\u0422\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b <a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/kotlinx-coroutines-core\/kotlinx.coroutines.flow\/state-in.html\"><u>Flow.stateIn<\/u><\/a> \u0438 <a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/kotlinx-coroutines-core\/kotlinx.coroutines.flow\/share-in.html\"><u>Flow.shareIn<\/u><\/a> \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441 <a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/kotlinx-coroutines-core\/kotlinx.coroutines.flow\/-sharing-started\/index.html\"><u>\u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043e\u0431\u0449\u0435\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0430<\/u><\/a>. <a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/kotlinx-coroutines-core\/kotlinx.coroutines.flow\/-sharing-started\/-while-subscribed.html\"><u>WhileSubscribed()<\/u><\/a> \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u0435\u0439! \u041d\u0430\u043f\u0440\u043e\u0442\u0438\u0432, <a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/kotlinx-coroutines-core\/kotlinx.coroutines.flow\/-sharing-started\/-eagerly.html\"><u>Eagerly<\/u><\/a> \u0438\u043b\u0438 <a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/kotlinx-coroutines-core\/kotlinx.coroutines.flow\/-sharing-started\/-lazily.html\"><u>Lazily<\/u><\/a> \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0430\u043a\u0442\u0438\u0432\u0435\u043d CoroutineScope, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442.<\/p>\n<blockquote>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> API, \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0445\u043e\u0440\u043e\u0448\u0438\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0434\u0435\u0442\u0430\u043b\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0442\u043e\u043a\u0430. \u042d\u0442\u0438 API \u0434\u0435\u043b\u0430\u044e\u0442 \u0442\u043e, \u0447\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u044b: \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0430\u044e\u0442 \u0441\u0431\u043e\u0440, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043d\u0435 \u0432\u0438\u0434\u0435\u043d \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435. \u042d\u0442\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043f\u043e\u0442\u043e\u043a\u0430, \u0434\u043e\u043b\u0436\u0435\u043d \u043b\u0438 \u043e\u043d \u0431\u044b\u0442\u044c \u0432\u0441\u0435\u0433\u0434\u0430 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u0438\u043b\u0438 \u043d\u0435\u0442.<\/p>\n<\/blockquote>\n<h3>\u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u0441\u0431\u043e\u0440 Flow \u0432 Jetpack Compose<\/h3>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <a href=\"https:\/\/developer.android.com\/reference\/kotlin\/androidx\/compose\/runtime\/package-summary#collectasstate\"><u>Flow.collectAsState<\/u><\/a> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 Compose \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0438\u0437 \u043a\u043e\u043c\u043f\u043e\u043d\u0443\u0435\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u0432\u0438\u0434\u0435 <a href=\"https:\/\/developer.android.com\/reference\/kotlin\/androidx\/compose\/runtime\/State\"><u>State&lt;T&gt;<\/u><\/a> \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 (UI) <code>Compose<\/code>. \u0414\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 <code>Compose<\/code> \u043d\u0435 \u043f\u0435\u0440\u0435\u043a\u043e\u043c\u043f\u043e\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u0442 UI, \u043a\u043e\u0433\u0434\u0430 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0445\u043e\u0441\u0442\u0430 \u0438\u043b\u0438 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0444\u043e\u043d\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435, \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0432\u0441\u0435 \u0435\u0449\u0435 \u0430\u043a\u0442\u0438\u0432\u0435\u043d \u0438 \u043c\u043e\u0436\u0435\u0442 \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b. <code>Compose<\/code> \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u044b\u0442\u044b\u0432\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0447\u0442\u043e \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f (View).<\/p>\n<p>\u041f\u0440\u0438 \u0441\u0431\u043e\u0440\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0432 <code>Compose<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>Flow.flowWithLifecycle<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"kotlin\">@Composable fun LocationScreen(locationFlow: Flow&lt;Flow&gt;) {      val lifecycleOwner = LocalLifecycleOwner.current     val locationFlowLifecycleAware = remember(locationFlow, lifecycleOwner) {         locationFlow.flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED)     }      val location by locationFlowLifecycleAware.collectAsState()      \/\/ Current location, do something with it }<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432\u0430\u043c <a href=\"https:\/\/developer.android.com\/jetpack\/compose\/state\"><u>\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f<\/u><\/a> \u043f\u043e\u0442\u043e\u043a <a href=\"https:\/\/developer.android.com\/jetpack\/compose\/state\"><u>remember<\/u><\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u043d\u0430\u0435\u0442 \u043e \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u043c \u0446\u0438\u043a\u043b\u0435, \u0441 <code>locationFlow<\/code> \u0438 <code>lifecycleOwner<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u044e\u0447\u0435\u0439, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043f\u043e\u0442\u043e\u043a, \u0435\u0441\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u043a\u043b\u044e\u0447\u0435\u0439 \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f.<\/p>\n<p>\u0412 Compose \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0432 <a href=\"https:\/\/developer.android.com\/jetpack\/compose\/lifecycle#state-effect-use-cases\"><u>\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u0441\u0440\u0435\u0434\u0435<\/u><\/a>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <a href=\"https:\/\/developer.android.com\/reference\/kotlin\/androidx\/compose\/runtime\/package-summary#launchedeffect_1\"><u>LaunchedEffect<\/u><\/a>, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0437\u0430 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u043c \u0446\u0438\u043a\u043b\u043e\u043c \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u0412 \u0435\u0435 \u0431\u043b\u043e\u043a\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 <code>Lifecycle.repeatOnLifecycle<\/code>, \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0430 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0430 \u0431\u043b\u043e\u043a \u043a\u043e\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0445\u043e\u0441\u0442\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c <code>State<\/code>.<\/p>\n<h3>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0441 LiveData<\/h3>\n<p>\u0412\u044b \u043c\u043e\u0433\u043b\u0438 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 API \u0432\u0435\u0434\u0435\u0442 \u0441\u0435\u0431\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e <a href=\"https:\/\/developer.android.com\/topic\/libraries\/architecture\/livedata\"><u>LiveData<\/u><\/a>, \u0438 \u044d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0430\u043a! <code>LiveData<\/code> \u0437\u043d\u0430\u0435\u0442 \u043e <code>Lifecycle<\/code>, \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0433\u043e \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u043c \u0434\u043b\u044f \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f \u0437\u0430 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430. \u042d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u0441\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432\u043e \u0434\u043b\u044f API <code>Lifecycle.repeatOnLifecycle<\/code> \u0438 <code>Flow.flowWithLifecycle<\/code>!<\/p>\n<p>\u0421\u0431\u043e\u0440 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u0438\u0445 API \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u043c\u0435\u043d\u043e\u0439 <code>LiveData<\/code> \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0445 <em>\u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 Kotlin<\/em>. \u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u044d\u0442\u0438 API \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, <code>LiveData<\/code> \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432 \u043f\u0435\u0440\u0435\u0434 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438 \u0438 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043f\u043e\u0442\u043e\u043a\u0438 \u0431\u043e\u043b\u0435\u0435 \u0433\u0438\u0431\u043a\u0438\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0438\u0437 \u043b\u044e\u0431\u043e\u0433\u043e <code>Dispatcher<\/code>, \u0438 \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0435\u0433\u043e <a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/kotlinx-coroutines-core\/kotlinx.coroutines.flow\/-flow\/\"><u>\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u043c\u0438<\/u><\/a>. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 <code>LiveData<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u0435\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u044e\u0442\u0441\u044f \u0438\u0437 \u043f\u043e\u0442\u043e\u043a\u0430 UI.<\/p>\n<h3>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 StateFlow \u0432 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p>\u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043e\u0434\u043d\u0430 \u0438\u0437 \u043f\u0440\u0438\u0447\u0438\u043d, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u044b, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 LiveData, \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u0422\u0430\u043a \u0432\u043e\u0442, <a href=\"https:\/\/developer.android.com\/kotlin\/flow\/stateflow-and-sharedflow\"><u>StateFlow<\/u><\/a> \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u0435\u0442 \u0442\u0430\u043a\u0443\u044e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443! \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0435 <code>StateFlow<\/code> \u0432 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 <a href=\"https:\/\/developer.android.com\/topic\/libraries\/data-binding\/observability#stateflow\"><u>\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u044c\u0442\u0435\u0441\u044c \u0441 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0435\u0439<\/u><\/a>.<\/p>\n<p><strong>. &nbsp; &nbsp; &nbsp; . &nbsp; &nbsp; &nbsp; .<\/strong><\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 API <code>Lifecycle.repeatOnLifecycle<\/code> \u0438\u043b\u0438 <code>Flow.flowWithLifecycle<\/code> \u0434\u043b\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e \u0441\u0431\u043e\u0440\u0430 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0432 Android.<\/p>\n<hr>\n<blockquote>\n<p>\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u0432 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u0443\u0440\u0441\u0430 <a href=\"https:\/\/otus.pw\/Ln8c\/\">&#171;Android Developer. Basic&#187;<\/a>.<\/p>\n<\/blockquote>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/564050\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/564050\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0434\u043b\u044f Android <a href=\"https:\/\/developer.android.com\/kotlin\/flow\"><u>\u043f\u043e\u0442\u043e\u043a\u0438 Kotlin<\/u><\/a> \u043e\u0431\u044b\u0447\u043d\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435. \u041e\u0434\u043d\u0430\u043a\u043e, \u0441\u043e\u0431\u0438\u0440\u0430\u044f \u044d\u0442\u0438 \u043f\u043e\u0442\u043e\u043a\u0438 (flows) \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0431\u043e\u0442\u044b, \u0447\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e, \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b (\u043a\u0430\u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430, \u0442\u0430\u043a \u0438 \u043f\u0430\u043c\u044f\u0442\u0438) \u0438\u043b\u0438 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0443\u0442\u0435\u0447\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0432 \u0444\u043e\u043d\u043e\u0432\u044b\u0439 \u0440\u0435\u0436\u0438\u043c.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0432\u044b \u0443\u0437\u043d\u0430\u0435\u0442\u0435, \u043a\u0430\u043a API <code>Lifecycle.repeatOnLifecycle<\/code> \u0438 <code>Flow.flowWithLifecycle<\/code> \u0437\u0430\u0449\u0438\u0449\u0430\u044e\u0442 \u0432\u0430\u0441 \u043e\u0442 \u043f\u0443\u0441\u0442\u043e\u0439 \u0442\u0440\u0430\u0442\u044b \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u0438\u0445 \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430.<\/p>\n<p><strong>. &nbsp; &nbsp; &nbsp; . &nbsp; &nbsp; &nbsp; .<\/strong><\/p>\n<h3>\u041d\u0435\u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432<\/h3>\n<p><a href=\"https:\/\/developer.android.com\/kotlin\/coroutines\/coroutines-best-practices#coroutines-data-layer\"><u>\u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f<\/u><\/a> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c API Flow&lt;T&gt; \u0441 \u043d\u0438\u0436\u043d\u0438\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0434\u0435\u0442\u0430\u043b\u0435\u0439 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u043f\u043e\u0442\u043e\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0442\u0430\u043a\u0436\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0438\u0445.<\/p>\n<p>\u0425\u043e\u043b\u043e\u0434\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0439 <a href=\"https:\/\/kotlinlang.org\/docs\/channels.html\"><u>\u043a\u0430\u043d\u0430\u043b\u043e\u043c<\/u><\/a> \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0441 \u0431\u0443\u0444\u0435\u0440\u0430\u043c\u0438, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a <a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/kotlinx-coroutines-core\/kotlinx.coroutines.flow\/buffer.html\"><u>buffer<\/u><\/a>, <a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/kotlinx-coroutines-core\/kotlinx.coroutines.flow\/conflate.html\"><u>conflate<\/u><\/a>, <a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/kotlinx-coroutines-core\/kotlinx.coroutines.flow\/flow-on.html\"><u>flowOn<\/u><\/a> \u0438\u043b\u0438 <a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/kotlinx-coroutines-core\/kotlinx.coroutines.flow\/share-in.html\"><u>shareIn<\/u><\/a>, \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c<strong> <\/strong>\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u0437 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 API, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a <a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/kotlinx-coroutines-core\/kotlinx.coroutines\/launch.html\"><u>CoroutineScope.launch<\/u><\/a>, <a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/kotlinx-coroutines-core\/kotlinx.coroutines.flow\/launch-in.html\"><u>Flow&lt;T&gt;.launchIn<\/u><\/a> \u0438\u043b\u0438 <a href=\"https:\/\/developer.android.com\/reference\/kotlin\/androidx\/lifecycle\/LifecycleCoroutineScope\"><u>LifecycleCoroutineScope.launchWhenX<\/u><\/a>, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u0432, \u0435\u0441\u043b\u0438 \u0432\u044b \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u0442\u0435 Job, \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0432\u0448\u0438\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443, \u043a\u043e\u0433\u0434\u0430 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0432 \u0444\u043e\u043d. \u042d\u0442\u0438 API \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c, \u043f\u043e\u043a\u0430 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u044d\u043c\u0438\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 \u0431\u0443\u0444\u0435\u0440 \u0432 \u0444\u043e\u043d\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u0445\u043e\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u044b.<\/p>\n<blockquote>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u0425\u043e\u043b\u043e\u0434\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u2014 \u044d\u0442\u043e \u0442\u0438\u043f \u043f\u043e\u0442\u043e\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0431\u043b\u043e\u043a \u043a\u043e\u0434\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u0430.<\/p>\n<\/blockquote>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u044d\u0442\u043e\u0442 \u043f\u043e\u0442\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0434\u0430\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/kotlinx-coroutines-core\/kotlinx.coroutines.flow\/callback-flow.html\"><u>callbackFlow<\/u><\/a>:<\/p>\n<pre><code class=\"kotlin\">\/\/ Implementation of a cold flow backed by a Channel that sends Location updates fun FusedLocationProviderClient.locationFlow() = callbackFlow&lt;Location&gt; {     val callback = object : LocationCallback() {         override fun onLocationResult(result: LocationResult?) {             result ?: return             try { offer(result.lastLocation) } catch(e: Exception) {}         }     }     requestLocationUpdates(createLocationRequest(), callback, Looper.getMainLooper())         .addOnFailureListener { e -&gt;             close(e) \/\/ in case of exception, close the Flow         }     \/\/ clean up when Flow collection ends     awaitClose {         removeLocationUpdates(callback)     } }<\/code><\/pre>\n<blockquote>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u0412\u043d\u0443\u0442\u0440\u0438 <code>callbackFlow<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <a href=\"https:\/\/kotlinlang.org\/docs\/reference\/coroutines\/channels.html\"><u>\u043a\u0430\u043d\u0430\u043b<\/u><\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Queue_(abstract_data_type)\"><u>\u043e\u0447\u0435\u0440\u0435\u0434\u044c<\/u><\/a> \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0438 \u0438\u043c\u0435\u0435\u0442 \u0435\u043c\u043a\u043e\u0441\u0442\u044c \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 64 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430.<\/p>\n<\/blockquote>\n<p>\u0421\u0431\u043e\u0440 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043b\u044e\u0431\u043e\u0433\u043e \u0438\u0437 \u0432\u044b\u0448\u0435\u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044b\u0445 API \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 \u0438\u0445 \u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435! \u0421\u043c. \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"kotlin\">class LocationActivity : AppCompatActivity() {     override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)          \/\/ Collects from the flow when the View is at least STARTED and         \/\/ SUSPENDS the collection when the lifecycle is STOPPED.         \/\/ Collecting the flow cancels when the View is DESTROYED.         lifecycleScope.launchWhenStarted {             locationProvider.locationFlow().collect {                 \/\/ New location! Update the map             }          }         \/\/ Same issue with:         \/\/ - lifecycleScope.launch { \/* Collect from locationFlow() here *\/ }         \/\/ - locationProvider.locationFlow().onEach { \/* ... *\/ }.launchIn(lifecycleScope)     } }<\/code><\/pre>\n<p><code>lifecycleScope.launchWhenStarted<\/code> \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b. \u041d\u043e\u0432\u044b\u0435 \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f, \u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c <code>callbackFlow<\/code> \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 API <code>lifecycleScope.launch<\/code> \u0438\u043b\u0438 <code>launchIn<\/code> \u0435\u0449\u0435 \u0431\u043e\u043b\u0435\u0435 \u043e\u043f\u0430\u0441\u043d\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043e\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0444\u043e\u043d\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435! \u0427\u0442\u043e \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043e\u0442\u043a\u0430\u0437\u0443 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0441 \u044d\u0442\u0438\u043c\u0438 API, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u0441\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u0442 \u0432 \u0444\u043e\u043d\u043e\u0432\u044b\u0439 \u0440\u0435\u0436\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c <code>callbackFlow<\/code> \u0438 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0433\u043e, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0431\u0443\u0434\u0435\u0442 \u044d\u043c\u0438\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438 \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e:<\/p>\n<pre><code class=\"kotlin\">class LocationActivity : AppCompatActivity() {      \/\/ Coroutine listening for Locations     private var locationUpdatesJob: Job? = null      override fun onStart() {         super.onStart()         locationUpdatesJob = lifecycleScope.launch {             locationProvider.locationFlow().collect {                 \/\/ New location! Update the map             }          }     }      override fun onStop() {         \/\/ Stop collecting when the View goes to the background         locationUpdatesJob?.cancel()         super.onStop()     } }<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043d\u043e \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434, \u0434\u0440\u0443\u0437\u044c\u044f! \u0418 \u0435\u0441\u043b\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u0441\u0435\u043e\u0431\u0449\u0430\u044f \u0438\u0441\u0442\u0438\u043d\u0430 \u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u0445 Android, \u0442\u043e \u043e\u043d\u0430 \u0442\u0430\u043a\u043e\u0432\u0430, \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u0435 \u043b\u044e\u0431\u0438\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434. \u041e\u0434\u043d\u043e \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432 \u043e\u0442\u043a\u0430\u0437\u0430 \u043e\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043e\u0434\u0430 \u043c\u0435\u043d\u044c\u0448\u0435 \u0448\u0430\u043d\u0441\u043e\u0432 \u0441\u043e\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443!<\/p>\n<h3>Lifecycle.repeatOnLifecycle<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0440\u0438\u0448\u043b\u0438 \u043a \u0435\u0434\u0438\u043d\u043e\u043c\u0443 \u043c\u043d\u0435\u043d\u0438\u044e \u0438 \u0437\u043d\u0430\u0435\u043c, \u0433\u0434\u0435 \u043a\u0440\u043e\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u043d\u0430\u0441\u0442\u0430\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c 1) \u043f\u0440\u043e\u0441\u0442\u044b\u043c, 2) \u0434\u0440\u0443\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0438\u043b\u0438 \u043b\u0435\u0433\u043a\u0438\u043c \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u044f\/\u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f, \u0438, \u0447\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0432\u0430\u0436\u043d\u043e, 3) \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c! \u041e\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0434\u0435\u0442\u0430\u043b\u0435\u0439 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043f\u043e\u0442\u043e\u043a\u0430.<\/p>\n<p>\u0411\u0435\u0437 \u043b\u0438\u0448\u043d\u0438\u0445 \u0441\u043b\u043e\u0432, API, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u044d\u0442\u043e <code>Lifecycle.repeatOnLifecycle<\/code>, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0439 \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 <a href=\"https:\/\/developer.android.com\/jetpack\/androidx\/releases\/lifecycle\"><u>lifecycle-runtime-ktx<\/u><\/a>.<\/p>\n<blockquote>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u042d\u0442\u0438 API \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 <code>lifecycle:lifecycle-runtime-ktx:2.4.0-alpha01<\/code> \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0437\u0434\u043d\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438.<\/p>\n<\/blockquote>\n<p>\u0412\u0437\u0433\u043b\u044f\u043d\u0438\u0442\u0435 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"kotlin\">class LocationActivity : AppCompatActivity() {     override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)          \/\/ Create a new coroutine since repeatOnLifecycle is a suspend function         lifecycleScope.launch {             \/\/ The block passed to repeatOnLifecycle is executed when the lifecycle             \/\/ is at least STARTED and is cancelled when the lifecycle is STOPPED.             \/\/ It automatically restarts the block when the lifecycle is STARTED again.             lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {                 \/\/ Safely collect from locationFlow when the lifecycle is STARTED                 \/\/ and stops collection when the lifecycle is STOPPED                 locationProvider.locationFlow().collect {                     \/\/ New location! Update the map                 }             }         }     } }<\/code><\/pre>\n<p><code>repeatOnLifecycle<\/code> \u2014 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0430\u044f <a href=\"https:\/\/developer.android.com\/reference\/android\/arch\/lifecycle\/Lifecycle.State\"><u>Lifecycle.State<\/u><\/a> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043d\u043e\u0432\u043e\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0441 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u043c \u0435\u0439 \u0431\u043b\u043e\u043a\u043e\u043c, \u043a\u043e\u0433\u0434\u0430 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442 \u044d\u0442\u043e\u0433\u043e <code>state<\/code>, \u0438 \u043e\u0442\u043c\u0435\u043d\u044b \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0435\u0439 \u044d\u0442\u043e\u0442 \u0431\u043b\u043e\u043a, \u043a\u043e\u0433\u0434\u0430 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u043f\u0430\u0434\u0430\u0435\u0442 \u043d\u0438\u0436\u0435 <code>state<\/code>.<\/p>\n<p>\u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043a\u043e\u0434, \u0434\u043b\u044f \u043e\u0442\u043c\u0435\u043d\u044b \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u0430, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>repeatOnLifecycle<\/code>. \u041a\u0430\u043a \u0432\u044b \u043c\u043e\u0433\u043b\u0438 \u0434\u043e\u0433\u0430\u0434\u0430\u0442\u044c\u0441\u044f, \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 API \u0432 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 <code>onCreate<\/code> \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 <code>onViewCreated<\/code> \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f. \u0421\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0438\u0436\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<pre><code class=\"kotlin\">class LocationFragment: Fragment() {     override fun onViewCreated(view: View, savedInstanceState: Bundle?) {         \/\/ ...         viewLifecycleOwner.lifecycleScope.launch {             viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {                 locationProvider.locationFlow().collect {                     \/\/ New location! Update the map                 }             }         }     } }<\/code><\/pre>\n<p><strong>\u0412\u0430\u0436\u043d\u043e:<\/strong> \u0424\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b <em>\u0432\u0441\u0435\u0433\u0434\u0430 <\/em>\u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>viewLifecycleOwner<\/code> \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a <code>DialogFragments<\/code>, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u043d\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0431\u044b\u0442\u044c View. \u0414\u043b\u044f <code>DialogFragments<\/code> \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>lifecycleOwner<\/code>.<\/p>\n<blockquote>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u042d\u0442\u0438 API \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 <code>lifecycle:lifecycle-runtime-ktx:2.4.0-alpha01<\/code> \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0437\u0434\u043d\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438.<\/p>\n<\/blockquote>\n<p><strong>\u041a\u043e\u043f\u043d\u0435\u043c \u0433\u043b\u0443\u0431\u0436\u0435!<\/strong><\/p>\n<p><code>repeatOnLifecycle<\/code> \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0443\u044e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443, \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0431\u043b\u043e\u043a, \u043a\u043e\u0433\u0434\u0430 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0432 \u0442\u0430\u0440\u0433\u0435\u0442 <code>state<\/code> \u0438 \u0438\u0437 \u043d\u0435\u0433\u043e \u0432 \u043d\u043e\u0432\u0443\u044e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443, \u0438 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0443\u044e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443, \u043a\u043e\u0433\u0434\u0430 Lifecycle \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0435\u0442\u0441\u044f. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u0443\u043d\u043a\u0442 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u0435\u043d: \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <code>repeatOnLifecycle<\/code>, \u043d\u0435 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u0438\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d.<\/p>\n<pre><code class=\"kotlin\">class LocationActivity : AppCompatActivity() {     override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)          \/\/ Create a coroutine         lifecycleScope.launch {                          lifecycle.repeatOnLifecycle(Lifecycle.State.RESUMED) {                 \/\/ Repeat when the lifecycle is RESUMED, cancel when PAUSED             }              \/\/ `lifecycle` is DESTROYED when the coroutine resumes. repeatOnLifecycle             \/\/ suspends the execution of the coroutine until the lifecycle is DESTROYED.         }     } }<\/code><\/pre>\n<h3>\u0412\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0430<\/h3>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f\u0441\u044c \u043a \u043d\u0430\u0447\u0430\u043b\u0443, \u0441\u0431\u043e\u0440 <code>locationFlow<\/code> \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0437 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u043e\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>lifecycleScope.launch<\/code>, \u0431\u044b\u043b \u043e\u043f\u0430\u0441\u0435\u043d, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u043b\u0441\u044f, \u0434\u0430\u0436\u0435 \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0432 \u0444\u043e\u043d\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435.<\/p>\n<p><code>repeatOnLifecycle<\/code> \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0440\u0430\u0442\u0443 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0438 \u0441\u0431\u043e\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0441\u0431\u043e\u0440 \u043f\u043e\u0442\u043e\u043a\u0430, \u043a\u043e\u0433\u0434\u0430 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0432 \u0442\u0430\u0440\u0433\u0435\u0442-\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e.<\/p>\n<figure class=\"full-width\"><figcaption>\u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438 \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c API repeatOnLifecycle<\/figcaption><\/figure>\n<h3>Flow.flowWithLifecycle<\/h3>\n<p>\u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>Flow.flowWithLifecycle<\/code>, \u043a\u043e\u0433\u0434\u0430 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430. \u042d\u0442\u043e\u0442 API \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <code>repeatOnLifecycle<\/code>, \u044d\u043c\u0438\u0442\u0438\u0440\u0443\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438 \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f, \u043a\u043e\u0433\u0434\u0430 Lifecycle \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0432 \u0442\u0430\u0440\u0433\u0435\u0442-\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0438\u0437 \u043d\u0435\u0433\u043e.<\/p>\n<pre><code class=\"kotlin\">class LocationActivity : AppCompatActivity() {     override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)          \/\/ Listen to one flow in a lifecycle-aware manner using flowWithLifecycle    <\/code><\/pre>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-325293","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/325293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=325293"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/325293\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=325293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=325293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=325293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}