I am calling a dialog with arguments as follows:
MyDialog("title", "message").show(this@MyActivity.supportFragmentManager, null)
And this is my dialog class:
class MyDialog(private val theTitle: String, private val theMessage: String) : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return activity.let {
val myBuilder = AlertDialog.Builder(it)
myBuilder
.setTitle(theTitle)
.setMessage(theMessage)
.setPositiveButton("OK") { _, _ -> }
myBuilder.create()
}
}
}
But when the orientation of device changes on rotation, the app stops working. That doesn't happen if no arguments are passed. So, how to pass arguments and what is the best way to do so?