Android – setRequestedOrientation – Activity and views lifecycle Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Android – setRequestedOrientation – Activity and views lifecycle without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I’m having some trouble with native code using JNI and I suspect that this is maybe due to a call to setRequestedOrientation().

What happens to the activity when I call setRequestedOrientation()? Is it just restarted or is it entirely destroyed?

Also, what happens the to views? If in onCreate I have :

protected void onCreate( Bundle savedInstanceState )
    super.onCreate( savedInstanceState );

        this.setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE );

        setContentView( R.layout.activity_XXX );
        mTermScreenView = (TermScreenView) findViewById( );

What happens to the View object? Is it recreated? Does it already exist when I call findViewById()? Is another View recreated after the screen gets rotated?


When you setRequestedOrientation() the view may be restarted.

Change the desired orientation of this activity. If the activity is currently in the foreground or otherwise impacting the screen orientation, the screen will immediately be changed (possibly causing the activity to be restarted). Otherwise, this will be used the next time the activity is visible.

When you rotate your screen or change the orientation, by default android will destroy and recreate the view.

We are here to answer your question about Android – setRequestedOrientation – Activity and views lifecycle - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji