I have Requirement to OnBackPressed
From Activity to MainActivity Fragment
. What I have Done to achieve this is Implement a Simple super.onbackPressed
. This super.onbackPressed
Bring Activity to Previous Activity.
I have Also done this, But My Requiremts does not matched to this, i.e OnBackpressed Activity to MainActivity Fragment..
override fun onBackPressed() {
val builder: AlertDialog.Builder = AlertDialog.Builder(this)
builder.setMessage(getString(R.string.doyouwanttoclose))
.setCancelable(false)
.setTitle("Alert!!")
.setNegativeButton("No",
DialogInterface.OnClickListener { dialog, id -> dialog.cancel() })
.setPositiveButton("Yes",
DialogInterface.OnClickListener { dialog, id -> this@MakeStylishActivity.finish() })
val alert: AlertDialog = builder.create()
alert.show()
}
I have Also Implemented these Solutions available on Stackoverflow but doesn't worked for me On Back Pressed in Android Fragments
How to detect when back button pressed in fragment android?..
I am Confused How this must Be Done, Or this is Not Possible..