安卓:启动屏幕没有得到显示,为什么? [英] Android: The splash screen does not get shown, why?

查看:174
本文介绍了安卓:启动屏幕没有得到显示,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作学习的Andr​​oid。从文档我读到目前为止,我无法弄清楚如何让飞溅视图来显示(睡眠屏幕保持空白期间)。看来我要开始为主要布局的新的活动,但这似乎浪费(闪应该一去不复返了,我想重新使用它的线程)。

 进口android.app.Activity;
进口android.os.Bundle;
进口android.util.Log;公共类Ext3的延伸活动{    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.splash);        Log.v(Ext3的,开始睡觉);        尝试{
            视频下载(5000);
        }赶上(InterruptedException的E){
            // TODO自动生成catch块
            e.printStackTrace();
        }        Log.v(Ext3的,做睡觉);        的setContentView(R.layout.main);
    }}


解决方案

我相信你的闪屏永远不会被显示,因为你永远不给UI线程(你是)一个抽奖机会,因为你只是睡那里什么都不做

取而代之的是视频下载的,我建议你寻找到一个定时器或东西这样的安排刷新和改变你的观点的内容;一种选择是启动的AsyncTask 的在那里你可以改变视图之前睡觉,你正在做的现在。

不睡觉或以任何其他方式阻止UI线程,这是很糟糕......(导致ANR)

I am working on learning Android. From the documents I have read so far I can't figure out how to get the splash View to show (during the sleep the screen stays blank). It appears I need to start a new activity for the main layout, but this seems wasteful (the splash should be forever gone, I'd like to reuse its thread).

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class Ext3 extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        Log.v("Ext3", "starting to sleep");

        try {
            Thread.sleep (5000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        Log.v("Ext3", "done sleeping");

        setContentView (R.layout.main);
    }

}

解决方案

I believe your splash screen never gets shown because you never give the UI thread (that you are in) a chance to draw it since you just sleep there doing nothing.

Instead of the Thread.sleep, I would suggest you look into a Timer or something like that to schedule the refresh and changing the content of your view; an alternative would be to start an AsyncTask where you could sleep before changing the view as you are doing now.

Do not sleep or in any other way block the UI thread, that's bad... (causes ANR)

这篇关于安卓:启动屏幕没有得到显示,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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