First of all thank you for your clarification, but I think you have not read my post well.
I don't see any problem here. It is just the normal Android process life cycle.
To my knowledge, the life cycle does not kill services if applications in the background and rarely in the foreground, you can read the tutorials that are on it, for example here.
http://www.b4x.com/android/forum/threads/service-modules.7542/
It is important to understand how Android chooses which process to kill when it is low on memory (a new process will later be created as needed).
A process can be in one of the three following states:
- Foreground - The user currently sees one of the process activities.
- Background - None of the activities of the process are visible, however there is a started service.
- Paused - There are no visible activities and no started services.
Sub Service_Create is called when the service is first started. This is the place to initialize and set the process global variables. Once a service is started it stays alive until you call StopService or until the whole process is destroyed.
Is your "reset/clear memory" done with a task killer?
I do not kill the task, that makes
ExitApplication
If you start a service with StartServiceAt() only an alarm is added to the system that your service should be started at the given time.
When the alarm fires there are two possibilities then:
1. Your process is still alive which means only Service_Start is called and your process_globals are still valid.
2. Your process was killed from the system which means process_globals is cleared and Service_Create is called where you should reinitialize your process_globals values.
All that you tell me I already know, and you again insist that
the system does not kill the Service, just reset the variables and re-enters Service create. If you look at the trace'll see.
Your app should always handle both situations.
If you had read my post you'd know that I have no problem with this, that my app already provides these two possibilities (and many more), I put this post to share with the rest of the forum and I saw something curious.
You can read it above:
And this I've tried in various terminals with different versions of Android, and it always happens.
In no time I have tried to comment lightly. This comment is based on many hours lost until finally saw the problem. And this problem I wanted to comment in the forum, because neither is a program problem, or B4A, it is as I said, of how Android manages the services. And if anyone wants to see that so is simply to make the trace I have indicated. That if the problem is likely not going to go to the first, and for that reason have to spend many hours as I lost.
This don't make sense. StartService will only be called when the program is ready to process messages. But with ExitApplication you kill the process before the message queue can be handled. Never ever use ExitApplication except you know exactly what you are doing. In 99,999% of all apps ExitApplication is not needed and will just cause problems!
The 100,000000% of times I have called :
StartService (ServicioPruebas)
ExitApplication
The service works , there has not been one single time not to go, because if I had seen so outside in the log , trace , etc, etc, etc.
On the other hand , as I said at the beginning, this is a little test I did at one moment Erel request , and the important thing is not color of buttons or as the program is done , the important thing is that when I make a clear memory from the phone , sometimes , not always, reset the variables , but DOES NOT KILL THE SERVICE. If there is a problem with the ExitApplication , he had seen in the log and trace, and as I say , at no time did.
As we have the example , change it for a Activity.Finish, memory load with various applications, and then erases the memory , and checks if it exists in "running processes" , and if not, possibly see what I 'm talking about consulting the log or trace. It is normal to not kill the service (at no time out "Service_Destroy" ) but to re-enter Service Create? I think not , and have not read in any place where I say that without destroying or stopping the service must reenter Service Create
Vielen Dank
Regards