Behaviour of Modal Dialogs on Activity Pause

thedesolatesoul

Expert
Licensed User
Longtime 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.
B4X:
Sub UploadFile
   Dim cd As CustomDialog 
      retPath = File.DirRootExternal 
      Populatelv(retPath,customLV,LVFolderOnly)
      cd.AddView(customLV,2dip,0,90%x-4dip,65%y)
      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")
         Return
      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...
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This means that customLV is still a child of the custom dialog, but isnt the custom dialog destroyed since it is a local variable?
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.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime 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.
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.
 
Upvote 0
Top