Maybe you can achieve this by using wake locks:
Wake locks allow your application to control the power state of the host device.
Creating and holding wake locks can have a dramatic impact on the host
device's battery life. Thus you should use wake locks only when
strictly necessary and hold them for as short a time as possible.
...
One legitimate case for using a wake lock might be a background service
that needs to grab a wake lock to keep the CPU running to do work
while the screen is off.
EDIT
If you are using the phonegap framework, Dave Alden created a plugin for "partial wakelocks" but this was in 2013 and the plugin seems to be no longer in github, but his answer still has the code...
It would help if you mentioned the framework you are using, but I suspect you may have to deal with wake locks one way or another (if the framework abstracts their usage, the better)...