open fragment from activity kotlin

// Import necessary packages
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction

class YourActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // Create an instance of your fragment
        val yourFragment = YourFragment()

        // Get the support fragment manager
        val fragmentManager: FragmentManager = supportFragmentManager

        // Begin a new transaction
        val transaction: FragmentTransaction = fragmentManager.beginTransaction()

        // Replace the container with the fragment
        transaction.replace(R.id.fragment_container, yourFragment)

        // Add the transaction to the back stack
        transaction.addToBackStack(null)

        // Commit the transaction
        transaction.commit()
    }
}

class YourFragment : Fragment() {

    // Fragment code goes here

}