Android Question Process Variables lose value??

Discussion in 'Android Questions' started by ducphu, Jan 28, 2015.

  1. ducphu

    ducphu Active Member Licensed User

    Hi all,

    In my app, there are 1 main activity and 1 child activity. I declare a process variable, let say "check as boolean" The child activity is called by the code:

    Sub Btn_Click
    if a > 10 then check = False
    else check = true
    End Sub
    Base on the value of "check", child_activity will display a blank textbox, if "check" = true or display a text if "check" = false. When I first run the app, "check" is assigned to false. My child activity opens and shows the text as normal. Then I press Home button and it for a while then open my app again. What I saw is my child activity with a blank textbox.

    From my understanding, as the app when I re-open, shows my child_activity, it means the app is still alive, not being killed by the OS. But then if my app is alive, how come my process variable lost its value ?
  2. sorex

    sorex Expert Licensed User

    try storing the value again to the label in Sub Activity_Resume.

    I believe some things get erased at some events, edit text might be one of them not sure about labels.
  3. ducphu

    ducphu Active Member Licensed User

    Hi sorex, which value do you mean? My child_activity doesn't contain only a textbox but others like spinner, checkbox... they all have same issue.
  4. eps

    eps Well-Known Member Licensed User

    Check the logs, you should see your process being destroyed - it won't sit there forever I'm afraid. You can store and restore values in a number of ways...

    1) A text file, write the value on Pause and re-read on Process Create

    2) There is some code that Erel provide, StateManager I think, search for this

    3) a DB (a bit excessive, but would work)
  5. sorex

    sorex Expert Licensed User

    rotate you phone and you will probably have the same result of form elements that get empty again.

    so you have to store them at pause and re-store them at resume I guess.
  6. ducphu

    ducphu Active Member Licensed User

    Hi eps, I understand that the process will be killed by the OS after sometime. I want to clarify 2 points:

    1. If I re-open my app and see my child_activity, does it mean the app is still alive?
    2. If the app is alive, will, in any case, process variables lose their values?
  7. ducphu

    ducphu Active Member Licensed User

    Unfortunately I design my app only support portrait...
  8. klaus

    klaus Expert Licensed User

    Post a small project showing the problem and we will have a look at it.
  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