Android Question Service and loadResource

Emme Developer

Well-Known Member
Licensed User
Longtime User
Hi all!
I'm trying to understand how service works properly. As i understood, resource should be load in started service. But if have to need a list that is used in another service and i don't want to clean? Need i to store it in a file/db/other stuff?

I put this flow as example.
I start the Starter service and start A service after 5 seconds.
I close my app and swipe it from recent list, so when A service will run, also starter service will run for second times.
I open my app, so starter service will run for third times.
I lost my list, because it was reinizialized 3 times..

If i initialize the list in Service_Create, nothing will change, because service will create every time i re open my app

How avoid this?
I attach a simple project. Thanks
 

Attachments

  • TryServic.zip
    8.1 KB · Views: 125

Emme Developer

Well-Known Member
Licensed User
Longtime User
Service_Create of the starter service will run exactly once when the process is created. It will never reinitialize a list as the list will always be uninitialized when Service_Create of the starter service runs.
Thanks for your answer. But I don't understand why, I have starter service inizialized more than one times, for example when I close and re open the app, but the list is still alive because I send a log of it from another service that starts every 5 seconds. I put all in attached example, maybe I can't explain clear what I mean
 
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Longtime User
You should put the code in Service_Create not Service_Start.


Service_Create will only be called again if the process was killed.
I already tried to put initialize list in service_create, but nothing seems to change. If i close and reopen app, i will get a new inizialization of list
 
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Longtime User
I tried different things, and i think i understood how it works. Every time i close the app and swipe it from recents, i close the process. When i re open it, all variable will get a new initialization. Now my question is, if have an event, and i want to call a service aftr 2 hours, how can i do this? I suppose that there can be another event that need to call service before 2 hours, so i think i need to store the scheduler list to keep the times when to launch the service, in order by to calculate rightly when service will start
 
Upvote 0
Top