brummton-info / HummFinder-Application

0 stars 0 forks source link

Matching Activity: onbackpressed() not working after preference datastore #2

Closed arnabeshd closed 2 years ago

arnabeshd commented 2 years ago

Overriding onBackPressed() as menu item.

override fun onOptionsItemSelected(item: MenuItem): Boolean {
        val frequency = viewModel.TGFrequency.toString()
        val level = viewModel.TGLevel.toString()
        when (item.itemId){
            android.R.id.home -> onBackPressed() /*onBackPressed() override*/
            R.id.misave -> viewModel.saveToDataStore(frequency,level)
            R.id.givefeedback -> Toast.makeText(this,"Thanks for your feedback",Toast.LENGTH_SHORT).show()
            R.id.closeapp -> finish()
        }
        return true
    }