Closed kkrawczyk123 closed 3 years ago
Hello @grzesiek2010, you have been unassigned from this issue because you have not updated this issue or any referenced pull requests for over 15 days.
You can reclaim this issue or claim any other issue by commenting @opendatakit-bot claim
on that issue.
Thanks for your contributions, and hope to see you again soon!
I reckon we could solve this by moving these dialogs to using DialogFragment
rather than AlertDialog
. This would mean the dialogs should be recreated when the Activity goes through the configuration changes (as far as I'm aware).
Hie @seadowg! Can I work on this?
@SaumiaSinghal sure! Go ahead and claim it! I'd look at the DialogFragment
s we're already using like ProgressDialogFragment
and MaterialFullScreenDialogFragment
and their tests to get a sense of how to work with the DialogFragment
. We've also got some helpers that will be useful for opening/closing DialogFragment
instances in DialogUtils
.
@opendatakit-bot claim
Hello @SaumiaSinghal, you have been unassigned from this issue because you have not updated this issue or any referenced pull requests for over 15 days.
You can reclaim this issue or claim any other issue by commenting @opendatakit-bot claim
on that issue.
Thanks for your contributions, and hope to see you again soon!
We talked a while ago about being more lenient with these, as it's a lot of investment for little gain to keep dialogs on screen during configuration changes. Closing this, but we can create separate issues if anyone feels one of these cases needs to be fixed.
Ok After working on this for 1 Week I found the solution:
Of course the correct solution to above issue is DialogFragement Still there was some issues I was facing as I wanted to make it resusable and sometimes it was not dismissing after any system change like rotating, changing of dark to light mode (Was able to continue appearing in screen but dismissing was disabled) etc..
This problem will resolve issues :
class ConfirmDialogWithYesAndNo(private val confirmDialogTitleText:String="Default Confirm Dialog Title",private val confirmDialogMessageText:String="Default Confirm Dialog Message",private val confirmDialogPositiveButtonText:String="Yes",private val confirmDialogNegativeButtonText:String="No",private val confirmDialogPositiveButtonClickListener:()->Unit= {},private val confirmDialogNegativeButtonClickListener:()->Unit= {}): DialogFragment(){
//Must keep this global
private lateinit var alertDialog: AlertDialog
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//Must use this otherwise after system change it will not dismiss and won't have same text which you passed.
retainInstance = true
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
super.onCreateDialog(savedInstanceState)
//Normal Dialog creation and return it
val builder = AlertDialog.Builder(requireActivity())
builder.setTitle(confirmDialogTitleText)
builder.setMessage(confirmDialogMessageText)
builder.setIcon(android.R.drawable.ic_dialog_alert)
builder.setPositiveButton("Yes") { _, _ ->
//In case you use custom layout
alertDialog.dismiss()
confirmDialogPositiveButtonClickListener()
}
builder.setNegativeButton("No") { _, _ ->
//In case you use custom layout button
confirmDialogNegativeButtonClickListener()
}
val alertDialog: AlertDialog = builder.create()
alertDialog.setCancelable(false)
alertDialog.show()
return alertDialog
}
}
class MainActivity : AppCompatActivity() {
....
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
.....
butoon.setOnClickListener {
val confirmDialogWithYesAndNo= ConfirmDialogWithYesAndNo("Hiii T","Hi Message","Yess B","No B",{
Toast.makeText(this,"Yesss",Toast.LENGTH_LONG).show()
},{
Toast.makeText(this,"Noo",Toast.LENGTH_LONG).show()
})
confirmDialogWithYesAndNo.showNow(this.supportFragmentManager,"anyrandomstring")
...
}
....
}
}
To contact or to check this code example : vaibhavmojidra.github.io/site/
Software and hardware versions
Collect v1.25.1, Android v4 -10.x.x, device used...
Problem description
Displayed dialogs are disappearing after screen rotation.
Dialogs: Exit form dialog Remove this response Layer data file dialog on geowidgets with map Input method dialog on geotrace and geoshape dialog Change Admin Password Dialog
Steps to reproduce the problem
Expected behavior
Dialogs should not disappear after rotating the screen.
Other information
I have noticed behavior differences between Android 8.1, 9.0 and other devices on Collect 1.23.3 - dialogs are not disappearing on them after rotating the screen. From 1.24.0 it occurs on all devices.