package Ġcom . example . kotlin navig ations ample Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġandroidx . navigation . Nav Controller Ċ import Ġandroidx . navigation . Navigation Ċ import Ġcom . example . kotlin navig ations ample . main . Example Ċ import Ġcom . example . kotlin navig ations ample . main . Main Fragment Ċ Ċ class ĠMainActivity Ġ: ĠAppCompatActivity (), ĠMain Fragment . On Item Interaction Listener Ġ{ ĊĠ Ġprivate Ġlateinit Ġvar Ġmain Nav Controller : ĠNav Controller ĊĊĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠ ĠsetContentView ( R . layout . activity _ main ) ĊĠĠĠ Ġmain Nav Controller Ġ= ĠNavigation . find Nav Controller ( this , ĠR . id . main Nav Fragment ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Support Navigate Up (): ĠBoolean Ġ= ĊĠĠĠ Ġmain Nav Controller . navigate Up () Ġ|| Ġsuper . on Support Navigate Up () ĊĊĠ Ġoverride Ġfun Ġon Item Interaction ( item ID : ĠInt ) Ġ{ ĊĠĠĠ Ġwhen Ġ( item ID ) Ġ{ ĊĠĠĠĠĠ ĠExample . BASIC _ NAV Ġ-> ĠR . id . action _ main Fragment _ to _ basic Navigation Activity ĊĠĠĠĠĠ ĠExample . BOTTOM _ NAV Ġ-> ĠR . id . action _ main Fragment _ to _ bottom Navigation Activity ĊĠĠĠĠĠ ĠExample . DRAW ER _ NAV Ġ-> ĠR . id . action _ main Fragment _ to _ drawer Navigation Activity ĊĠĠĠĠĠ ĠExample . DE EP _ NAV Ġ-> ĠR . id . action _ main Fragment _ to _ deep Link Navigation Activity ĊĠĠĠĠĠ ĠExample . SAFE _ ARGS Ġ-> ĠR . id . action _ main Fragment _ to _ safe Args Navigation Activity ĊĠĠĠĠĠ ĠExample . CONDITION AL _ NAV Ġ-> ĠR . id . action _ main Fragment _ to _ conditional Navigation Activity ĊĠĠĠĠĠ Ġelse Ġ-> Ġthrow ĠRuntimeException (" Invalid ĠExample : Ġ$ item ID ") ĊĠĠĠ Ġ}. apply ( main Nav Controller :: navigate ) ĊĠ Ġ} Ċ } Ċ