Android Question Life cycle question

wl

Well-Known Member
Licensed User
Longtime User
Hi,

Assume I have an app with an activity and a service.
In the Process_Globals of the service I define a variable and in the activity I reference it.

Will the service be created/started when I reference the variable in the activity ?

Thanks
 

tunderin

Member
Licensed User
Longtime User
The service will not be started when you reference the variable from the activity.

Is that to say that if code in the service gives value to the referenced variable, that the value returned to the activity will be wrong?
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Process Globals are executed when the process is created, it does/should not matter which module you put the declaration in.
The service will not be created by referencing a process globals variable.
The value returned to the activity will be whatever the initial value of that variable is (set to in Process Globals).
 
Reactions: wl
Upvote 0

tunderin

Member
Licensed User
Longtime User
As an afterthough, I wondered about what happens when an activity calls a non-running service sub and am left with the impression that nothing that an activity does with the service will cause the service to be created/started short of calling StartService or CallSubDelayed.

Is that correct?
 
Last edited:
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Almost.
But you can also use CallSubDelayed which is a combination of StartService + CallSub.
From the docs,
 
Upvote 0

tunderin

Member
Licensed User
Longtime User
We crossed paths, I remembered CallSubDelay and was editing my post while you were responding...

Thanks for the clarification - coming from desktop, life-cycle is probably the most nebulous concept for me to get my head around in coming to Android.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…