简体   繁体   English

Android快速应用旋转崩溃

[英]Android fast app rotation crash

When i am logged in android application, and fast rotating screen, app can't handle onSaveInstanceState and onCreate(loading user and performing login). 当我登录android应用程序并快速旋转屏幕时,应用程序无法处理onSaveInstanceState和onCreate(加载用户并执行登录)。 So i get logged out. 所以我注销了。 Can i somehow handle rotations, and not allowing to call those methods so quick? 我可以以某种方式处理旋转,并且不允许这么快地调用这些方法吗?

When you rotates the device your Activity will re-create and all the variables will be re-initialized. 旋转设备时,将重新创建“活动”,并将重新初始化所有变量。 So, in that case if you want to some values to remain same on Rotation also you can store their state using the onSaveInstanceState() and you can restore in onCreate() again by checking Bundle is not null. 因此,在这种情况下,如果您希望某些值在Rotation上保持不变,则还可以使用onSaveInstanceState()存储它们的状态,并且可以通过检查Bundle不为null来再次在onCreate()中进行还原。

if(savedInstanceState != null){
            // get the restore value from the Bundle
        }

Where as onConfigurationChanged() will be called when you rotate the Device(Note that this will only be called if you have selected configurations you would like to handle with the This method is called when screen rotated 旋转设备时将调用onConfigurationChanged()的位置(请注意,仅当您选择了要使用此方法处理的配置时,才会调用此方法。

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
        //Do stuff here
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM