简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM