【问题标题】:how to wait for splash screen will be finished如何等待启动画面完成
【发布时间】:2012-09-26 07:34:13
【问题描述】:

我想等待启动画面完成他的任务,然后继续进行活动。 我认为我的错误是因为等待启动画面的时间太多,我的启动画面是为了从服务器获取一些字符串,它有所有需要。 创建并需要等待启动画面完成的第一类是: 更新:

            Thread splashTread = new Thread() {
                @Override
                public void run() {
                    try {
                        splash  splash=(tools.splash) new splash(first.this).execute();
                        int waited = 0;
                        while(splash.running && (waited< getResources().getInteger(R.integer.splashTimeOut)))
                        {
                            sleep(100);
                            if(splash.running) {
                                waited += 100;
                            }
                            // nextActivity=splash.newActivity;
                        }
                    } catch(InterruptedException e) {
                        // do nothing
                    } finally {
                        finish();

                    }
                }
            };
            splashTread.start();

虽然闪屏没问题

  public class splash extends AsyncTask<String, Void, String>

这是错误的,因为它创建了一个新的活动,然后执行线程......

【问题讨论】:

    标签: android android-asynctask splash-screen


    【解决方案1】:
    public void onCreate(Bundle savedInstanceState) {
       protected boolean _active = true;
       protected int _splashTime = 1000;
      super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
    
    
        Thread splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    int waited = 0;
                    while(_active && (waited < _splashTime)) {
                        sleep(100);
                        if(_active) {
                            waited += 100;
                        }
                    }
                } catch(InterruptedException e) {
                    // do nothing
                } finally {
                    finish();
    
                }
            }
        };
        splashTread.start();
    

    【讨论】:

    • 我在主帖上更新了我的代码,但似乎它仍在进行下一个活动,而不是等待线程(启动画面)
    【解决方案2】:

    希望我的代码对你有所帮助

    public void onStart() 
        {
            super.onStart();
    
            Thread background = new Thread(new Runnable() 
            {
                public void run() 
                {
                    try
                    {
                        Thread.sleep(3000);
                        Intent langSelect = new Intent(EduApp.this, LanguageActivity.class);
                        startActivity(langSelect);
                        genHelper.goForwardScreen();
                    }
                    catch (Throwable t) 
                    {               
                        System.err.println("Thread Exception IN Splash Screen->" + t.toString());
                    }
                }
            });
            background.start();
        }
    

    在此处开始下一个活动..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-11
      • 1970-01-01
      相关资源
      最近更新 更多