Android Question Process Variables lose value??

ducphu

Active Member
Licensed User
Longtime 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:

B4X:
Sub Btn_Click
    if a > 10 then check = False
    else check = true
    StartActivity(Child_Activity)
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 ?
 

sorex

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

ducphu

Active Member
Licensed User
Longtime 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.
 
Upvote 0

eps

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

sorex

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

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.
 
Upvote 0

ducphu

Active Member
Licensed User
Longtime 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?
 
Upvote 0

ducphu

Active Member
Licensed User
Longtime 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.

Unfortunately I design my app only support portrait...
 
Upvote 0
Top