Android - setRequestedOrientation - Activity and views lifecycle

北城余情 提交于 2020-01-02 06:57:28

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/33173162/android-setrequestedorientation-activity-and-views-lifecycle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!