How to continue running while Android screen is locked

I’m using draw() loop to send repetitively HTTP requests. Everything works fine. But as soon as the phone times out and goes into lock mode. The draw loop is no longer running.
What should I use in order to keep my sketch running while screen is locked?

Just tried it with tread() that seems to do the job.
But since I’m new in this I also love to hear other suggestions.