简体   繁体   English

在Android中,在第一次启动手机应用程序时,活动前白屏显示

[英]In android getting white screen before activity when first time app start on phone

Here is my source code of launcher activity. 这是我的启动器活动源代码。 I search a lot on stack overflow but nothing getting good answer 我在堆栈溢出中搜索了很多,但没有任何好的答案

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_lang);

        init();
    }

  private void init(){
        spnLanguage = (Spinner)findViewById(R.id.spnLanguage);
        btnNext = (Button)findViewById(R.id.btnNext);
        btnNext.setOnClickListener(this);

    }

Android apps do take some amount of time to start up, especially on a cold start. Android应用确实需要花费一些时间才能启动,尤其是冷启动时。 There is a delay there that you may not be able to avoid 有一个延迟,您可能无法避免

https://www.bignerdranch.com/blog/splash-screens-the-right-way/ https://www.bignerdranch.com/blog/splash-screens-the-right-way/

In the AndroidManifest file of your starting Activity, mention a transparent Theme 在开始的Activity的AndroidManifest文件中,提及一个透明的Theme

<activity
    android:name="Your activity name"
    android:theme="@android:style/Theme.Translucent.NoTitleBar" >
 <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

In my case delay was bit more. 就我而言,延迟要多一些。 After searching a lot I found that it is because of android studio auto run feature. 经过大量搜索后,我发现这是因为android studio自动运行功能。 After disabling the auto run issue is solved. 禁用自动运行后,问题得以解决。

I had a similar problem some time ago. 我前段时间也遇到过类似的问题。

The activity is displayed to the user when it reaches the onStart() method. 当活动到达onStart()方法时,该活动将显示给用户。 Your init() seems to take some time so until it finishes, you will only see the empty activity. 您的init()似乎要花一些时间,所以直到完成为止,您只会看到空的活动。

You could either trigger all heavy background work (that is not needed for the initial GUI setup) in a later method or first call another activity acting as splash screen if you have to keep all content of init() where it is. 您可以在以后的方法中触发所有繁重的后台工作(初始GUI设置不需要此工作),或者如果必须将init()所有内容都保留在原处,则可以先调用另一个充当初始屏幕的活动。

我也有同样的问题,请在下面的问题以及解决方法中找到: 在gradle构建中第一次显示白屏。

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

相关问题 尝试打开应用程序时出现白屏。 应用程序正在我的手机上启动而没有错误 - Getting white screen when trying to open the app. App is getting launched on my phone without errors 每当应用程序来自android中的后台时,启动“第一屏幕” - Start the First screen each time app comes from background in android Android Studio 启动画面在活动开始前消失 - Android Studio Splash screen disappearing before activity start 启动前 Android 白屏 - Android White Screen on Before Splash 我试图在模拟器中运行该应用程序,但未显示第一个活动。 它只是打开并显示白屏 - I tried to run the app in the emulator but its not showing the first activity. it just opens and shows a white screen android arraylist应用白屏 - android arraylist app white screen 每次我开始上一个活动时Android应用程序崩溃 - Android app crashes every time i start the previous activity 每次启动或恢复时,Android应用程序/活动是否完全启动? - Android App/Activity To Start Fresh Completely every time it starts or resumes? 在非活动类中获取Android应用启动时间 - Get Android App Start Time in a non-activity class 在Android中避免在Webview之前出现白屏 - Avoid White Screen before Webview in Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM