Android Question Service question

FFMan

Member
Licensed User
Longtime User
Have been converting one 2 apps to use a service and have a couple of questions:-

1) can an activity start multiple services ?
2) if yes to (1), can the variables be shared amongst the services, or only between a service and the parent app ?
3) can I start multiple copies of the same service but pass a parameter to make them access a different resource. e.g. I want to have a Bluetooth connection to 4 identical devices. So can I start a service and pass it a pointer that simply indicates which device (1-4) to talk to ?
4) if I can do (3), can I have a table shared amongst the parent app and all 4 services e.g. strData(1 to 4) so that activity app can access all the data in 1 table ?

I am liking services, even more if the answer to the above is yes,yes,yes.yes !

thanks
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,
I try not to be wrong :
1) yes, an activity can start / stop as many services you like
2) the variables can be shared when you declare them in Process_Globals. You point to them using the service or activity name prefix. For example: Main.MyVar or MyServ1.MyVar1, etc.
3) I would use a class to act like this but experts could complete my reply
4) it's one of the Map or Type's usage

I do like services too
 
Upvote 0

FFMan

Member
Licensed User
Longtime User
1) good
2) ok so if I had strTemp in each service, I reference it by <service_name>.strTemp. But if my services are all the same name as they are the same code, just started 4 times, how would this work ? I guess I could duplicate the code 4 times each with a different name and index. Not too much work once the code is finalised.
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
2) I don't well understand the question as I thought you were asking if you could share the same variable with all your services (all services getting the same value from the same variable). In this case, you could declare the variable one time only from one service or from one activity.
But if you want the same variable name but not sharing the same value, the class would reply to this need.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…