title: How to keep application awake in background
body: <p>I program an application, which is connected to bluetooth device and used in a car (in the background) and navigation (or something else) in the foreground.</p>
  
  <p>But on android 7+ (maybe also 6), application go to sleep after some time. When I'm trying to take picture from camera the "sleep mode" is immediately and my app is sleeping now (no bluetooth connection, no notifications) - just dead app. </p>
  
  <p>I must go to recent apps -> click on my app and this make the "wake up". Bluetooth is now connecting to device again.</p>
  
  <p>But I can't still check if the app is sleeping or not. So, how to keep app awake also in background?</p>
  
  <p>I read some about WakeLock, but it looks like it's not working, cause app still sleeping. BUút maybe I'm using it wrong.</p>
  
  <pre><code>PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
      wk = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "MyWakeLock");
      wk.acquire();
  </code></pre>
  
  <p>and onDestroy</p>
  
  <pre><code>wk.release();
  </code></pre>
  
  <p>Thanks</p>