I made an Android app that makes lots of stuff. One of them is GPS tracking, saving marks to draw a trail. Sometimes, Android closes my app when the phone is out of my sight in my pocket (I guess it's Android's "smart" memory management...??), and thus its GPS tracking stops.
I have used some tracking apps that keep running for long periods, so I guess they do something that I don't know.
How can I prevent this sudden stop? Can I add some kind of priority to the GPS tracking to prevent this, or some other way?
EDIT
Observe that I don't want just to get tracking even if app is closed. I want to prevent Android from closing the app, since the GPS tracking needs to be logged by the app.