Android - setRequestedOrientation - Activity 和视图生命周期
Android - setRequestedOrientation - Activity and views lifecycle
我在使用 JNI 的本机代码方面遇到了一些问题,我怀疑这可能是由于调用了 setRequestedOrientation()
。
当我调用 setRequestedOrientation()
时 activity 会怎样?是刚刚重启还是彻底毁掉了?
此外,观看次数发生了什么变化?如果在 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 );
View 对象发生了什么变化?它是重新创建的吗?当我调用findViewById()
时它已经存在了吗?屏幕旋转后是否重新创建另一个视图?
当您设置 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
我在使用 JNI 的本机代码方面遇到了一些问题,我怀疑这可能是由于调用了 setRequestedOrientation()
。
当我调用 setRequestedOrientation()
时 activity 会怎样?是刚刚重启还是彻底毁掉了?
此外,观看次数发生了什么变化?如果在 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 );
View 对象发生了什么变化?它是重新创建的吗?当我调用findViewById()
时它已经存在了吗?屏幕旋转后是否重新创建另一个视图?
当您设置 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