Android Question How to Keep public variable when device get into deep sleep

karyadi

Member
Licensed User
Longtime User
Hi All,

i have a question,
How to Keep public variable when device get into deep sleep?
because every time my device get into deep sleep, all my variable become null.

thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
These two variables, are kept forever (until the app is closed or killed by OS of course) or can happen the app RESUME with NULL in them ?
No and yes.

test2 is an activity variable. Its life cycle is tied to the activity life cycle. However it will never be "null" as you are setting it correctly in Activity_Create.

Rules of thumb:
- All non-ui global variables should be process global variables and set when FirstTime is true.
- All public process globals should be declared in the starter service and set in Service_Create sub.
 
Upvote 0

An Schi

Well-Known Member
Licensed User
- All non-ui global variables should be process global variables and set when FirstTime is true.

Is it dangerous to set them everytime the app starts and not only when FirsTime is true?


@marcick : Thanks for keep on digging here :)
Sometimes i'm just doing things and when there are questions i see that i don't understand what i am doing.... :oops:
Maybe this is a good topic for a new tutorial written by an expert ;)
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
I had to rewrite my first app: i distributed variables everywhere with no real plan, so some of them was lost in activity pause and some where retained because declared in services. As I always say: "results are unpredictable" when you code in such a way.
 
Upvote 0
Top