title: How to completely prevent Android Lock Screen
body: <p>I made an field guide app for biology. It does tons of stuff, for example, recordings of wildlife sounds, and it is made to run the whole day with a single battery charge.</p>
  <p>Since it is intended to be run a whole day, I cannot keep the screen on all the time. So naturally the screen goes off. Then, the lock screen kicks in, blocking the app. Then you need to enter the pin/pattern/whatever and you then miss the opportunity of a precious recording. Dozens of times per day. And in general the user is using my app in the wild, where there is much less risk of theft.</p>
  <p>So I present the user an option in the preference section of my app to turn lock screen off while using it. There is no problem with this (see below for the code I made), except that when I switch to a secondary activity the lock screen appears. It is not truly a &quot;lock screen&quot;, in the sense that it shows the back button that when you press it the lock screen disappears. But still, a pain when you're in a hurry. I want <strong>no lock screen</strong>. At all.</p>
  <p>Interestingly, when I switch back to the primary activity from a secondary, no lock screen is shown...</p>
  <p>This is the way I found to (partially) disable the lock screen (executed in each activity <code>act</code>):</p>
  <pre><code>        if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O_MR1) {
              act.setShowWhenLocked(true);
              act.setTurnScreenOn(true);
              ((KeyguardManager) act.getSystemService(Context.KEYGUARD_SERVICE)).requestDismissKeyguard(act, null);
              //if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.Q) 
              //     act.setInheritShowWhenLocked(true);  // makes no difference?
          } else {
              Window window = act.getWindow();
              window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
              window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
          }
  </code></pre>
  <p>Of course, I also have in the Manifest:</p>
  <pre><code>&lt;uses-permission android:name=&quot;android.permission.DISABLE_KEYGUARD&quot;/&gt;
  </code></pre>