https://kotlinlang.org logo
#coroutines
Title
# coroutines
g

Gabriel Feo

02/08/2020, 8:09 PM
a

Anastasia Finogenova

02/09/2020, 3:13 AM
Depends on the scope the coroutine is laughed in, it may finish the execution of may be cancelled if the scope tied to the fragment lifecycle. Read the docs on the coroutine scopes to better understand.
g

Gabriel Feo

02/09/2020, 5:55 AM
Thanks, @Anastasia Finogenova. Makes sense. Did go through the docs again to see what I was missing
l

louiscad

02/09/2020, 8:13 AM
If you want to request runtime permissions, you might want to use #splitties permissions, where most of the work has been done for you.
g

Gabriel Feo

02/09/2020, 3:53 PM
Thanks, I didn’t know splitties. Will take a look at it. I wish to know if there’s any problems with my approach though, to see if I’m getting scopes right…
l

louiscad

02/09/2020, 8:23 PM
Well, I think you should not rely on a Fragment being nested for that use case. Splitties permissions are agnostic to that, plus handle a bug in the framework where you can get your Activity in a state where it can no longer request permissions. All you need is to use the lifecycleScope of viewLifecycleOwner in a Fragment or lifecycleScope in an Activity to run the coroutine where you request the permission.
6 Views