Partial wake lock releases when screen turns off
<p>Im building a Cordova/Ionic app which lets a user view the camera of an Andoroid cellphone live using webrtc (peerJs).</p>

<p>I need to allow the device to turn off the screen after (let's say) 15 seconds, and keep transmitting the video to other Android device.</p>

<p>As far as I know to deal with this problem I need to aquire a PARTIAL_WAKE_LOCK (This allows the screen to be turned off and keeps the app running), and never release it, so the app keeps sending me the video endlessly.</p>

<p>I decided to go for an Android native implementation, so i acquired the lock in the "onStart()" method, present in platforms\android\CordovaLib\src\org\apache\cordova\CordovaActivity.java with this code present in almost every tutorial</p>

<pre><code> PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
      wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
        "My wakelook");
      wakeLock.acquire();
</code></pre>

<p>I first tried the code above, aquiring a SCREEN_DIM_WAKE_LOCK. And it worked, the screen never turned off and It kept me sending the video endlessly. This makes me think that the wakelock adquisition is successful. When I changed the code to PARTIAL_WAKE_LOCK, the screen just turns off after 15 seconds and the video just freezes.</p>

<p>I've read that the class that acquires the wakelock has to extend "Application", but this class CordovaActivity extends Activity and I cant make it extend another class neither replace "Activity" with "Application". I dont know if this is neccesary since the code above works fine using SCREEN_DIM_WAKE_LOCK.</p>

<p>I tried using this plugin <a href="https://github.com/boltex/cordova-plugin-powermanagement" rel="nofollow">https://github.com/boltex/cordova-plugin-powermanagement</a> to aquire the partial wake lock, but it does just the same as above.</p>

<p>Thanks</p>