Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - setRequestedOrientation - Activity and views lifecycle

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 );

    try
    {
        this.setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE );

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

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?

like image 249
Virus721 Avatar asked Oct 16 '15 14:10

Virus721


1 Answers

When you setRequestedOrientation() the view may be restarted. http://developer.android.com/reference/android/app/Activity.html#setRequestedOrientation(int)

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. http://developer.android.com/guide/topics/resources/runtime-changes.html

like image 149
Ajanthan Hariharan Avatar answered Sep 21 '22 23:09

Ajanthan Hariharan