{"id":900,"date":"2025-10-29T04:08:37","date_gmt":"2025-10-29T04:08:37","guid":{"rendered":"https:\/\/nurlandroid.com\/?p=900"},"modified":"2025-10-29T04:08:37","modified_gmt":"2025-10-29T04:08:37","slug":"%d1%87%d1%82%d0%be-%d1%82%d0%b0%d0%ba%d0%be%d0%b5-coroutinescope-%d0%ba%d0%b0%d0%ba%d0%b8%d0%b5-%d0%b2%d0%b8%d0%b4%d1%8b-%d0%b7%d0%bd%d0%b0%d0%b5%d1%88%d1%8c","status":"publish","type":"post","link":"https:\/\/nurlandroid.com\/?p=900","title":{"rendered":"\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 CoroutineScope? \u041a\u0430\u043a\u0438\u0435 \u0432\u0438\u0434\u044b \u0437\u043d\u0430\u0435\u0448\u044c?"},"content":{"rendered":"\n<p><code><strong>CoroutineScope<\/strong><\/code> \u2014 \u044d\u0442\u043e <strong>\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d<\/strong>, \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u044e\u0449\u0430\u044f \u0438\u0445 \u0432 \u043e\u0434\u043d\u0443 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e. \u0422\u043e \u0435\u0441\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 <strong>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c<\/strong>. \u0414\u043b\u044f \u043b\u0435\u0433\u043a\u043e\u0441\u0442\u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0435\u0451 \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0441 <strong>Android<\/strong> <strong>Activity<\/strong>: \u043d\u0430\u0448\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u0441\u044f \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 <code><strong>CoroutineScope<\/strong><\/code>, \u0442\u0430\u043a \u0436\u0435 \u043a\u0430\u043a \u043d\u0430\u0448\u0438 \u0432\u044c\u044e\u0448\u043a\u0438(Textview, Button, Liene\u0430rLayout  \u0438 \u0434\u0440.) \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0439 Activity. \u0415\u0441\u043b\u0438 <code><strong>CoroutineScope<\/strong><\/code> \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f(\u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f), \u0442\u043e \u0432\u0441\u0435 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u0442\u0430\u043a \u0436\u0435 \u043e\u0442\u043c\u0435\u043d\u044f\u0442\u0441\u044f, \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0431\u044b \u0437\u0430\u043a\u0440\u044b\u0432 Activity \u043d\u0430\u0448\u0438 \u0432\u044c\u044e\u0448\u043a\u0438 \u0442\u0430\u043a \u0436\u0435 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u044e\u0442\u0441\u044f.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u0412\u0438\u0434\u044b CoroutineScope<\/h4>\n\n\n\n<p><strong>1. <code>CoroutineScope<\/code><\/strong> \u2014 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439(\u0431\u0430\u0437\u043e\u0432\u044b\u0439) \u0441\u043a\u043e\u0443\u043f, \u0434\u0430\u044e\u0449\u0438\u0439 \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c. \u041d\u0443\u0436\u043d\u043e \u0441\u0430\u043c\u043e\u043c\u0443 <strong>\u043e\u0442\u043c\u0435\u043d\u044f\u0442\u044c scope.cancel()<\/strong> \u043f\u0440\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438.<\/p>\n\n\n\n<p><strong>2. GlobalScope<\/strong> &#8212; \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f <strong>\u043e\u0434\u0438\u043d\u043e\u0447\u043d\u044b\u0445 \u0444\u043e\u043d\u043e\u0432\u044b\u0445 \u0437\u0430\u0434\u0430\u0447<\/strong>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0435\u0433\u043e \u043a\u0440\u0430\u0439\u043d\u0435 \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u043d\u0435 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d \u043a \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u043c\u0443 \u0446\u0438\u043a\u043b\u0443 \u0438 \u0438\u0437-\u0437\u0430 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0443\u0442\u0435\u0447\u043a\u0438 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n\n\n\n<p><strong>3. <code>viewModelScope<\/code> <\/strong>&#8212; \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 <code>androidx.lifecycle<\/code>. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0438\u0437 ViewModel \u0438 \u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 ViewModel.<code>onCleared()<\/code><\/p>\n\n\n\n<p><strong>4. lifecycleScope<\/strong> &#8212; \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u0434\u043b\u044f UI-\u0437\u0430\u0434\u0430\u0447, \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u0436\u0438\u0432\u0443\u0449\u0438\u0445 \u0437\u0430\u0434\u0430\u0447 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0432\u044c\u044e\u0448\u043a\u0438. \u041f\u0440\u0438\u0432\u044f\u0437\u0430\u043d \u043a \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u043c\u0443 \u0446\u0438\u043a\u043b\u0443 <code>LifecycleOwner<\/code> \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0432 <code>onDestroy()<\/code><\/p>\n\n\n\n<p><strong>5. supervisorScope<\/strong> &#8212; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0435 <strong>\u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b\u043e \u043a \u043e\u0442\u043c\u0435\u043d\u0435 \u0434\u0440\u0443\u0433\u0438\u0445 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043a\u043e\u0443\u043f\u0430.<\/strong><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>CoroutineScope \u2014 \u044d\u0442\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d, \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u044e\u0449\u0430\u044f \u0438\u0445 \u0432 \u043e\u0434\u043d\u0443 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e. \u0422\u043e \u0435\u0441\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c. \u0414\u043b\u044f \u043b\u0435\u0433\u043a\u043e\u0441\u0442\u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0435\u0451 \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0441 Android Activity: \u043d\u0430\u0448\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u0441\u044f \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 CoroutineScope, \u0442\u0430\u043a \u0436\u0435 \u043a\u0430\u043a \u043d\u0430\u0448\u0438 \u0432\u044c\u044e\u0448\u043a\u0438(Textview, Button, Liene\u0430rLayout \u0438 \u0434\u0440.) \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0439 Activity. \u0415\u0441\u043b\u0438 CoroutineScope \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f(\u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f), \u0442\u043e \u0432\u0441\u0435 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,23],"tags":[],"class_list":["post-900","post","type-post","status-publish","format-standard","hentry","category-android","category-coroutines"],"_links":{"self":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts\/900","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=900"}],"version-history":[{"count":2,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts\/900\/revisions"}],"predecessor-version":[{"id":902,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts\/900\/revisions\/902"}],"wp:attachment":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=900"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=900"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=900"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}