Android-setRequestedOrientation-活动和视图生命周期 [英] Android - setRequestedOrientation - Activity and views lifecycle

查看:513
本文介绍了Android-setRequestedOrientation-活动和视图生命周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用JNI的本机代码方面遇到了一些麻烦,我怀疑这可能是由于调用了setRequestedOrientation()造成的.

I'm having some trouble with native code using JNI and I suspect that this is maybe due to a call to setRequestedOrientation().

当我呼叫setRequestedOrientation()时,活动会如何?它只是重新启动还是被完全破坏了?

What happens to the activity when I call setRequestedOrientation()? Is it just restarted or is it entirely destroyed?

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

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

View对象会怎样?重新创建了吗?呼叫findViewById()时已经存在吗?旋转屏幕后是否会重新创建另一个视图?

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?

推荐答案

设置setRequestedOrientation()时,视图可能会重新启动. http://developer.android.com/reference/android/app/Activity.html#setRequestedOrientation(int)

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.

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

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-setRequestedOrientation-活动和视图生命周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆