I have android application with several services. This application should send reports to remote server when this application has been started and when has been stopped. But I don't know how to determine that application was stopped, because application may be stopped (crushed for example), but services still running. I think that the algorithm should be like this:
- Check the mark with last date from storage (and if this mark exists - send "stop" time to the server)
- Send "start" message to the server, when application was started
- Every 10 minutes application should writes current date and time mark on disk
If I will create service with this check - android can kill this single service when there is low memory, but application can be running. If I will create ScheduledExecutorService in Application class - application can stop, but services can be still running.
Can you help me with solution?