简体   繁体   English

Activity.OnCreate被调用两次

[英]Activity.OnCreate is called twice

In an Android app, the Splash screen of my app is called twice. 在一个Android应用程序中,我的应用程序的启动屏幕被调用了两次。

I have used ConfigChanges.Orientation | 我用过ConfigChanges.Orientation | ConfigChanges.ScreenSize | ConfigChanges.ScreenSize | ConfigChanges.KeyboardHidden to avoid recreation for screen orientation and other reasons, but it still is called twice. ConfigChanges.KeyboardHidden避免由于屏幕方向和其他原因而重新创建,但仍被调用两次。

Is there a function or way to get the reason about why is called twice? 是否有某种函数或方法可以得出为什么被调用两次的原因?

UPDATE: 更新:

I know it is called twice for a log file. 我知道日志文件被两次调用。 I want to avoid to be called twice because OnCreate initializes some global instances. 我想避免被调用两次,因为OnCreate会初始化一些全局实例。

if you rotate this device you activity will be recreate no matter what (This is expected behaviour). 如果旋转此设备,无论如何都会重新创建活动(这是预期的行为)。 using config flag you can only retain data on screen. 使用config标志,您只能在屏幕上保留数据。 if dont want activity to be recreated try with orientation lock for activity. 如果不想重新创建活动,请尝试使用活动方向锁定。

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

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