lateinit var fromActivity: FromActivity private const val FROM_ACTIVITY = "from_activity" enum class FromActivity { HOME, SEARCH_RESULT, ɾɾɾ } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) fromActivity = intent.getSerializableExtra(FROM_ACTIVITY) as FromActivity } override fun onOptionsItemSelected(item: MenuItem?): Boolean { when (item?.itemId) { android.R.id.home -> { val intent = createIntent(fromActivity) intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP navigateUpTo(intent) return true } else -> return false } } private fun createIntent(fromActivity: FromActivity): Intent { return when (fromActivity) { FromActivity.HOME -> Intent(this, HomeActivity::class.java) FromActivity.SEARCH_RESULT -> Intent(this, SearchItemResultActivity::class.java) ɾɾɾ } } }