2 years ago

#35564

test-img

jampooot

why onBackPressed() syntax is closing the app?

the onBackPressed() in the signup page is okay and i put the same code in another activity and when i pressed it, the app will go back to previous activity but it will close first..

this is the code in my second activity which the app will close after i press the back arrow

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    binding = ActivityAllusersignupBinding.inflate(layoutInflater)
    setContentView(binding.root)

    //action bar
    actionBar = supportActionBar!!
    actionBar.title = "User Registration"
    actionBar.setDisplayHomeAsUpEnabled(true)

}

override fun onSupportNavigateUp(): Boolean {
    onBackPressed()//go back to previous activity, when back button of actionbar clicked
    return super.onSupportNavigateUp()
}

}

android

kotlin

android-actionbar

onbackpressed

0 Answers

Your Answer

Accepted video resources