class MyActivity : AppCompatActivity()
{ override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_my)
// Check that the activity is using the layout version with
// the fragment_container FrameLayout if (findViewById<FrameLayout>
(R.id.fragment_container) != null) {
// However, if we're being restored from a previous state,
// then we don't need to do anything and should return or else
// we could end up with overlapping fragments. if (savedInstanceState != null) { return }
// Create an instance of ExampleFragment val firstFragment = MyFragment()
// Add the fragment to the 'fragment_container' FrameLayout
supportFragmentManager.beginTransaction() .add(R.id.fragment_container, firstFragment).commit() } } }