iOS Question B4XPages - save and restore page when taking pictures

cwt

Active Member
Licensed User
Longtime User
Using B4XPages with B4i - when the app takes a picture with the code below
B4X:
    Camera.TakePicture
    Dim TopPage As String = B4XPages.GetManager.GetTopPage.Id
    Wait For Camera_Complete (Success As Boolean, Image As Bitmap, VideoPath As String)
    B4XPages.GetManager.mStackOfPageIds.Add(TopPage) 'this is required as the page will be removed from the stack when the external camera page appears.
    If Success Then
        Dim bmp As B4XBitmap = Image
        bmp.Resize(TargetWidth, TargetHeight, True)
        CallSubDelayed3(Me, "Image_Available", True, bmp)
    Else
        CallSubDelayed3(Me, "Image_Available", False, Null)
    End If

the current page is removed from the stack and loaded again - but all views are cleared and anything entered via the UI is lost - is there a way to save the current page, including all variables, and restore again in this scenario? I know about save state but is there any easier way to do this?
 

cwt

Active Member
Licensed User
Longtime User
That should never happen. Try the example: B4X] [B4XPages] Intent based camera
Note that this line is not needed if you are using the latest version of B4XPages: B4XPages.GetManager.mStackOfPageIds.Add(TopPage)
Well, it is definitely happening with the camera I am using, which is from the CameraIntent.b4i example that I downloaded. When I take the picture and accept the picture on the camera page, the camera page is closed and the B4XPage is reloaded, thus giving me a new page without any UI data that was entered prior to taking the picture. In the B4XPage_Appear sub I am clearing all TextFields so the user can create a new record. So I expect everything already entered would be cleared, as is happening. The question is, is it normal behavior for this to happen - the page to reload itself after the camera page closes? The user can take pictures before the record has been saved to the SQLite database, so if the page is exited to take a picture and then reloaded, it has not yet been saved to the database. I supposed I can prevent the user from taking a picture before the initial save but that seems kind of clunky.

I am using B4XPages v1.05 with B4i v6.80
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
First step is to update to the latest version: https://www.b4x.com/android/forum/threads/updates-to-internal-libraries.48179/post-775787

thus giving me a new page without any UI data that was entered prior to taking the picture. In the B4XPage_Appear sub I am clearing all TextFields so the user can create a new record
Sounds like a mistake. There are all kinds of cases where the page will disappear and reappear. You don't want to clear the UI at this point. Clear the page when the user explicitly moves to a different page.
 
Upvote 0
Top