There is an application that contains the activity MainActivity . The activity is collecting GPS coordinates (in the background) and sending them to the server.
If you start the application and "forget" about it, then it works for a while (maximum hour), i.e. collects coordinates, and timers running in onCreate() work. Then the application hangs in the open, but does nothing, the log does not write. If you activate it, then everything works fine again.
I wrote a task for him through AlarmManager , so that every minute just write to the log. Creating a class object in which alarm is registered occurs in the overloaded onCreate() . After that, the application stopped falling asleep. However, on some devices it may still fall asleep after a few hours. In this case, the Alarm log is stable.
I decided to track the life cycle of the application and saw that after the main form becomes inactive, OnStop() and OnDestroy() always executed immediately. Those. processes continue to work after OnDestroy() . But then they can be put to sleep.
Please advise me how to periodically activate the application (maybe you can somehow initiate the onCreate() call) so that the processes started by the timers are not put to sleep. Thank.