android用欢迎界面加载运行环境

以前一直以为splash页只是图好玩..

今天才知道是应该把环境加载放在这个页面...

论坛和github上太多仿XXX的项目果然只能学习下ui的思路...

以前把环境加载放在application里面,难怪启动白屏要花那么长时间...

代码很简单,做一个线程,然后delay运行即可,如下:

  
public class SplashActvity extends AbstractActivity {

    private static final int sleepTime =4000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                //初始化服务
                long start = System.currentTimeMillis();
                initService();
                long costTime = System.currentTimeMillis() - start;
                if (sleepTime - costTime > 0) {
                    try {
                        Thread.sleep(sleepTime - costTime);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

                Log.d("splah act-------->","inited service");

                //界面跳转
                String token = AppContext.getInstance().getToken();
                if (TextUtils.isEmpty(token)) {
                    startActivity(SignInActivity.newIntent());
                } else {
                    startActivity(MainActivity.newIntent());
                }
                finish();
            }
        },500);
    }

    private void initService(){
        //注册环信通知
       AppContext.getInstance().initEnvir();
        //注册百度定位
        AppContext.getInstance().initLocation();
    }
}

 

posted @ 2016-03-04 00:00  保安保安  阅读(455)  评论(0编辑  收藏  举报