package Ġcom . ben ny hu o . android . activity stack . sample Ċ Ċ import Ġandroid . content . Intent Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . util . Log Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġcom . ben ny hu o . android . activity stack . Task Manager Ċ import Ġkotlinx . android . synt hetic . main . activity _ third .* Ċ Ċ class ĠThird Activity : ĠAppCompatActivity () Ġ{ ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠĠĠĠĠ ĠsetContentView ( R . layout . activity _ third ) ĊĊĠĠĠĠĠĠĠ ĠgetCurrent Activity . setOnClickListener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠLog . d (" as ", Ġ" current : Ġ${ Task Manager . getCurrent Activity () }") ĊĠĠĠĠĠĠĠĠĠĠĠ ĠLog . d (" as ", Ġ" foreground : Ġ${ Task Manager . is Foreground () }") ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġgoto Main . setOnClickListener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠstartActivity ( Intent ( this , ĠMainActivity :: class . java ). add Flags ( Intent . FLAG _ ACTIVITY _ NEW _ TASK ). add Flags ( Intent . FLAG _ ACTIVITY _ CLEAR _ TOP )) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġ} Ċ Ċ }