I implemented this function in the mainActivity of my app to ask to press back twice to exit the application, everything works but it asks me to double back press even when I want to close a fragment, how can I limit it only to the main screen?
override fun onBackPressed() {
if (backPressedTime + 2000 > System.currentTimeMillis()) {
super.onBackPressed()
}else{
Toast.makeText(this, "Premere ancora per tornare indietro", Toast.LENGTH_SHORT).show()
}
backPressedTime = System.currentTimeMillis()
}