Search code examples
androidandroid-activitykotlinbacktrace

Combine flags and clear back trace in kotlin


I am using Kotlin to develop an android application. In Android, we were using addFlags and setFlags to set flags and clear the backtrace activities separated by "|". How to achieve it in Kotlin? I am currently using below code in Kotlin:

startActivity(Intent(context, MyActivity::class.java)
            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK))

But it is not Working. I have also tried addFlags, It is also not working. What should be done in this scenario?


Solution

  • Use it like this

    val intent = Intent(context, MyActivity::class.java)                
    intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK