'How to close document and switch to default activity or launch it if not started?

I have a notification that should open activity and the user can accept or reject notification content as the user could receive multiple notifications, I'm opening every activity in document, this is how I open activity in document

    val intent = Intent().setClassName(
        applicationContext.packageName,
        "activityclassname"
    )
    intent.putExtra(PendingRequestFCM::class.java.simpleName,requestFCM)
    intent.flags = Intent.FLAG_ACTIVITY_NEW_DOCUMENT
    val pendingIntent = PendingIntent.getActivity(this, 0, intent, 0)
    return pendingIntent

this opens the activity but the problem is when the user take action I need to bring home activity to the top or open it if it's not open but every time I open it, it starts in the current document, making the user have 2 documents opened( 2 instances of the app in recent apps), so how to close the current document and open activity in default document?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source