有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Android setRequestedOrientation活动和视图生命周期

我在使用JNI的本机代码时遇到了一些问题,我怀疑这可能是由于调用了setRequestedOrientation()

当我调用setRequestedOrientation()时,活动会发生什么变化?它是刚刚重新启动还是完全销毁

另外,视图会发生什么变化?如果在onCreate中,我有:

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

视图对象会发生什么情况?它是重新创建的吗?当我调用findViewById()时,它是否已经存在?屏幕旋转后是否重新创建另一个视图


共 (1) 个答案

  1. # 1 楼答案

    设置RequestedOrientation()时,视图可能会重新启动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.

    当您旋转屏幕或更改方向时,默认情况下android将破坏并重新创建视图。 http://developer.android.com/guide/topics/resources/runtime-changes.html