[英]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.