# LifecycleScope - heartRateBpm - how to make stop and start function?

**URL:** <https://discuss.kotlinlang.org/t/lifecyclescope-heartratebpm-how-to-make-stop-and-start-function/24696>\
**Category:** Support\
**Created:** [April 25, 2022, 10:39am UTC](https://discuss.kotlinlang.org/t/lifecyclescope-heartratebpm-how-to-make-stop-and-start-function/24696 "2022-04-25T10:39:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mommek](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/mommek/32/9297_2.png) [@mommek](https://discuss.kotlinlang.org/u/mommek)\
**Post date:** [April 25, 2022, 10:39am UTC](https://discuss.kotlinlang.org/t/lifecyclescope-heartratebpm-how-to-make-stop-and-start-function/24696/1 "2022-04-25T10:39:02Z")

</div>

Hello there,

I have simple code for getting BPM rate (wear OS - watch app - kotlin):

```auto
fun onCreate(savedInstanceState: Bundle?)
{
...
   // Bind viewmodel state to the UI.
        lifecycleScope.launchWhenStarted {
            viewModel.uiState.collect {
                updateViewVisiblity(it)
            }
        }
        /*
        lifecycleScope.launchWhenStarted {
            viewModel.heartRateAvailable.collect {
                //binding.textView3.text = getString(R.string.measure_status, it)
            }
        }
        */

        lifecycleScope.launchWhenStarted {
            viewModel.heartRateBpm.collect {
                binding.lastMeasuredValue.text = String.format("%.0f", it)
            }
        }
...
}

```

This work, when I open my app. I just need create button with start / stop function. Can someone give me a hint how to? 🙂

Roman
