screen goes off while recording and preview gets corrupted

How do you prevent the screen from going off when recording is in process. If recording is in process, and there’s no other activity like using arrow keys, or the keypad, the screen goes off and when it’s brought back to life, the preview is corrupted.

Answer

What do you mean with “recording in progress”? You have an app that is recording something?
The easiest way (which doesn’t require any additional permissions) is to give any of your views android:keepScreenOn=true (there’s also setKeepScreenOn()).

If you want to be hardcore, you can request a wakelock permission, but that should not be necessary – if you have a UI, keepScreenOn is a much more elegant solution.