【问题标题】:unable to see splash screen while wating it will finished观看时无法看到启动画面将完成
【发布时间】:2012-09-26 09:44:36
【问题描述】:

我试图等到 spalsh 屏幕结束,然后当从 splash 获得结果时转到另一个活动但我的代码不等待启动 (AsyncTask) 只是为了之后的意图。 希望你能帮忙。

 lv.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            String nextActivity=new String();
            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;
                        }
                        Intent intent = new Intent(first.this,Class.forName("activities.third"));
                     startActivity(intent);
                    } catch(InterruptedException e) {
                        // do nothing
                    } catch (ClassNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } finally {
                        finish();

                    }
                }
            };
            splashTread.start();


            try {
                Intent intent = new Intent(first.this,Class.forName("activities.third"));
                 startActivity(intent);

【问题讨论】:

    标签: android android-asynctask splash-screen


    【解决方案1】:

    使用此代码

     Intent intent = new Intent(first.this,Class.forName("activities.third"));
                     startActivity(intent);
    

    finish() 之前的finally 内,而不是开始尝试块;

    【讨论】:

    • 我收到一个错误 09-26 08:44:14.738: E/AndroidRuntime(332): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()我认为因为 AsyncTask 有一个 gui
    • 然后使用 UIthread。参考这个stackoverflow.com/questions/6213538/…
    猜你喜欢
    • 1970-01-01
    • 2021-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-10
    • 1970-01-01
    相关资源
    最近更新 更多