Behaviour of Modal Dialogs on Activity Pause

Discussion in 'Android Questions' started by thedesolatesoul, Jul 2, 2012.

  1. thedesolatesoul

    thedesolatesoul Expert Licensed User

    I have to admit I dont really understand many things about this.
    This is more of a problem for Custom Dialogs than any others, but you never know.
    Sub UploadFile
    Dim cd As CustomDialog 
          retPath = 
          fdresp = cd.Show(
    "Select File to upload","Select","Cancel","",Null)
    If fdresp = -3 Then Return
    If File.IsDirectory(DB.GetParentPath(retPath),DB.GetFileName(retPath))= True Then
    ToastMessageShow("No file is selected"False)
    Log("Directory was selected instead of file")
    End If

    ToastMessageShow(DB.GetFileName(fname)  & " will be uploaded shortly",False)
    End Sub
    So when a CustomDialog is visible, and then the Home key is pressed, the modal dialog needs to be removed. I am not sure how B4A handles it from here. Does it just exit the current sub, or does it kill the dialog and return DialogResponse.Cancel and the code is allowed to run through?

    Either way, when I start my app again and invoke the same sub again, I get an error: IllegalStateException: The specified child already has a parent. You must call removeView() on the childs parent first.

    This means that customLV is still a child of the custom dialog, but isnt the custom dialog destroyed since it is a local variable?

    ...or maybe I am missing something basic here again...
  2. Erel

    Erel Administrator Staff Member Licensed User

    The dialog views cannot be destroyed as long as there is a reference to them. In this case there is at least one reference from customLV. You can call customLV.RemoveView to remove the view from its parent before adding it again.
  3. thedesolatesoul

    thedesolatesoul Expert Licensed User

    But so far I have never removed customLV from the Custom Dialog. Why does this work in normal operation i.e. if I do not pause the app when the dialog is visible? It only happens when the Activity is paused.
  4. thedesolatesoul

    thedesolatesoul Expert Licensed User