How to stop the screen rotation in android?

52 Views Asked by At

I want to prevent my app from the rotation, but I don't want to specify the screen Orientation in every activity tag in the manifest file instead I want to define it only once in my application which should work for the whole app. Is there any way to do that? Or I need to specify this in every activity?

1

There are 1 best solutions below

0
Hezy Ziv On

there is a way, you can create baseActivity and make all activities extend it.

open class BaseActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
    }
}

class MainActivity : BaseActivity() {
   
}