-1

I have a customDialog with input fields. I want possible entries to be removed once the dialog is closed (either via back or when a certain button is pressed), i.e. the state should not be saved.

How can I do that?

deimos1988
  • 5,896
  • 7
  • 41
  • 57

2 Answers2

1

If the back button is pressed means that dialog is canceled. Implement DialogInterface.OnCancelListener for your dialog and empty/delete/null the entries you want.

Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
0

I think you might be getting another problem.

Say that you have shown a dialog which was dismissed. If the same dialog is going to be shown a second time, it won't be rebuilt. It will just be shown again.

This means that if you setup your dialog in the onCreateDialog method, the second time that the dialog is shown, this method isn't invoked! Instead, onPrepareDialog is invoked.

Alternatives? You can call Activity.removeDialog or take care of the setup process in the onPrepareDialog hook.

Pedro Loureiro
  • 11,436
  • 2
  • 31
  • 37
  • What about implementing a onCancelListener, as he asked he needs to empty the entries done in the dialog, since back button/negative button will try to dismiss the dialog, so the dialog is canceled, so inside he can empty the entries. Right? Reasonable? – Nikola Despotoski Jul 24 '11 at 23:13
  • If the user presses "Ok" (assuming such button exists) won't invoke onCancel. I think this could be done in onDismiss, but at that time he wouldn't know which information he should put on the dialog to show the next time... – Pedro Loureiro Jul 24 '11 at 23:22
  • He said that entries are emptied/deleteded/null-ed if the dialog is closed. And we speak about that scenario. If we talk about the `OK` button according to previous scenario we can derive conclusion that there is no need to empty/delete the entries. – Nikola Despotoski Jul 24 '11 at 23:32
  • Ok, in that case it's possible, but I was suspecting that he would have the problem I described as soon as he would make a move – Pedro Loureiro Jul 24 '11 at 23:39