java Android - setRequestedOrientation - 活动和视图生命周期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33173162/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android - setRequestedOrientation - Activity and views lifecycle
提问by Virus721
I'm having some trouble with native code using JNI and I suspect that this is maybe due to a call to setRequestedOrientation()
.
我在使用 JNI 的本机代码时遇到了一些问题,我怀疑这可能是由于调用了setRequestedOrientation()
.
What happens to the activity when I call setRequestedOrientation()
? Is it just restarted or is it entirely destroyed?
当我打电话时,活动会发生什么setRequestedOrientation()
?它是刚刚重新启动还是完全被破坏了?
Also, what happens the to views? If in onCreate I have :
另外,视图会发生什么?如果在 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 );
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?
View 对象会发生什么?是重新创建的吗?我打电话时它已经存在了findViewById()
吗?屏幕旋转后是否重新创建了另一个视图?
回答by Ajanthan Hariharan
When you setRequestedOrientation() the view may be restarted. http://developer.android.com/reference/android/app/Activity.html#setRequestedOrientation(int)
当您 setRequestedOrientation() 时,视图可能会重新启动。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.
更改此活动的所需方向。如果 Activity 当前处于前台或以其他方式影响屏幕方向,屏幕将立即更改(可能导致 Activity 重新启动)。否则,这将在下次活动可见时使用。
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
当您旋转屏幕或更改方向时,默认情况下 android 将销毁并重新创建视图。 http://developer.android.com/guide/topics/resources/runtime-changes.html