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).
 
  • Like
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,
CallSubDelayed is a combination of StartActivity, StartService and CallSub.
Unlike CallSub which only works with currently running components, CallSubDelayed will first start the target component if needed.
CallSubDelayed can also be used to call subs in the current module. Instead of calling these subs directly, a message will be sent to the message queue.
The sub will be called when the message is processed. This is useful in cases where you want to do something "right after" the current sub (usually related to UI events).
Note that if you call an Activity while the whole application is in the background (no visible activities), the sub will be executed once the target activity is resumed.
 
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
Top