package Ġcom . squareup . sample . hello back button Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroidx . activity . view Models Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġandroidx . lifecycle . Saved State Handle Ċ import Ġandroidx . lifecycle . ViewModel Ċ import Ġandroidx . lifecycle . lifecycle Scope Ċ import Ġandroidx . lifecycle . viewModel Scope Ċ import Ġcom . squareup . sample . container . Sample Containers Ċ import Ġcom . squareup . workflow 1 . ui . Workflow Layout Ċ import Ġcom . squareup . workflow 1 . ui . Workflow Ui Experimental Api Ċ import Ġcom . squareup . workflow 1 . ui . modal . Alert Container Ċ import Ġcom . squareup . workflow 1 . ui . plus Ċ import Ġcom . squareup . workflow 1 . ui . render Workflow In Ċ import Ġkotlinx . coroutines . Job Ċ import Ġkotlinx . coroutines . flow . State Flow Ċ import Ġkotlinx . coroutines . launch Ċ Ċ @ Opt In ( Workflow Ui Experimental Api :: class ) Ċ private Ġval Ġview Registry Ġ= ĠSample Containers Ġ+ ĠAlert Container Ċ Ċ class ĠHello Back Button Activity Ġ: ĠAppCompatActivity () Ġ{ ĊĠ Ġ@ Opt In ( Workflow Ui Experimental Api :: class ) ĊĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĊĠĠĠ Ġval Ġmodel : ĠHello Back Button Model Ġby Ġview Models () ĊĠĠĠ ĠsetContentView ( ĊĠĠĠĠĠ ĠWorkflow Layout ( this ). apply Ġ{ Ġstart ( model . render ings , Ġview Registry ) Ġ} ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġlifecycle Scope . launch Ġ{ ĊĠĠĠĠĠ Ġmodel . waitFor Exit () ĊĠĠĠĠĠ Ġfinish () ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ Ċ class ĠHello Back Button Model ( saved State : ĠSaved State Handle ) Ġ: ĠViewModel () Ġ{ ĊĠ Ġprivate Ġval Ġrunning Ġ= ĠJob () ĊĊĠ Ġ@ Opt In ( Workflow Ui Experimental Api :: class ) ĊĠ Ġval Ġrender ings : ĠState Flow < Any > Ġby Ġlazy Ġ{ ĊĠĠĠ Ġrender Workflow In ( ĊĠĠĠĠĠ Ġworkflow Ġ= ĠAre You S ure Workflow , ĊĠĠĠĠĠ Ġscope Ġ= ĠviewModel Scope , ĊĠĠĠĠĠ Ġsaved State Handle Ġ= Ġsaved State ĊĠĠĠ Ġ) Ġ{ ĊĠĠĠĠĠ Ġ// ĠThis Ġworkflow Ġhandles Ġthe Ġback Ġbutton Ġitself , Ġso Ġthe Ġactivity Ġcan 't . ĊĠĠĠĠĠ Ġ// ĠInstead , Ġthe Ġworkflow Ġemits Ġan Ġoutput Ġto Ġsignal Ġthat Ġit 's Ġtime Ġto Ġshut Ġthings Ġdown . ĊĠĠĠĠĠ Ġrunning . complete () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ/** ĠBlocks Ġuntil Ġthe Ġworkflow Ġsignals Ġthat Ġit 's Ġtime Ġto Ġshut Ġthings Ġdown . Ġ*/ ĊĠ Ġsuspend Ġfun ĠwaitFor Exit () Ġ= Ġrunning . join () Ċ } Ċ