My app switches from MainActivity to ChatActivity when user presses a button. Problem is the back button on my toolbar won't do anything, while the default back button on UI works. Here's what I've tried:
Set these 2 options to true
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true)
Making MainActivity the parent of ChatActivity:
<activity android:name=".ChatActivity" android:parentActivityName=".MainActivity" />
The compiles and runs without any errors. Where am I going wrong here?
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
finish()
}
return super.onOptionsItemSelected(item)
}
This works fine add the above code in your activity