Android Question Serialize a Bundle

Discussion in 'Android Questions' started by DawningTruth, Apr 12, 2019.

  1. DawningTruth

    DawningTruth Active Member Licensed User

    I think this one is a long shot... but here goes...

    Is there any way to Serialise a Bundle, or to save a bundle to a file or database. I am trying to save the state of a webview for later use. Any help would be much appreciated :).
     
  2. Computersmith64

    Computersmith64 Well-Known Member Licensed User

    According to a reply I read from Erel in another thread, you cannot serialize views. Possibly one way you could do it would be to save references to the contents of the webview, but I'm guessing that might not be an option.

    - Colin.
     
    DawningTruth likes this.
  3. Computersmith64

    Computersmith64 Well-Known Member Licensed User

    DawningTruth likes this.
  4. DawningTruth

    DawningTruth Active Member Licensed User

    Thx Colin, read through it. The specific challenge I have is I need to save the back forward history. It can be extracted, but not reused. It can be saved into a bundle, but I don't know how to save a bundle in B4A. I have however seen people saving bundles in Android, so I assume there is some way yo do it.

    Here is the relevant stack overflow article:

    https://stackoverflow.com/questions/2598248/how-to-serialize-a-bundle
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    It depends on the bundle contents. The code in that link will only serialize simple values.
     
    DawningTruth likes this.
  6. DawningTruth

    DawningTruth Active Member Licensed User

    Thx Erel, any suggestions on how I could save one of those webview bundles?
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    You need to first understand which objects were added to the bundle. Use the debugger to find the bundle keys and values.
     
    DawningTruth likes this.
  8. DawningTruth

    DawningTruth Active Member Licensed User

    Thx Erel,

    Ok, I have setup a little project which puts some history into a webview and then saves its state into a bundle. Here is a screenshot from the debugger:

    [​IMG]

    I assume you would want to copy that mArray into a list and then save it to a list and then restore to a new bundle when needed.

    The question is:

    1. How do you access the mArray?
    2. How do you copy to the mArray of the new bundle?

    They both look like they are protected variables.
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Saving it to a list will not help. You need to serialize it to an array of bytes. I don't see how you can do it with this bundle.
     
    DawningTruth likes this.
  10. DawningTruth

    DawningTruth Active Member Licensed User

    Thx Erel, ok I will have to accept this technical limitation and try a slightly less functional workaround. Well at least we tried ;). Thx anyways:).
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice