【问题标题】:I want to use handler instead of timer for my splash activity我想为我的启动活动使用处理程序而不是计时器
【发布时间】:2014-02-24 18:31:30
【问题描述】:

目前我正在编写一个 Android 应用程序,并且我正在使用计时器进行启动。我想使用句柄而不是使用计时器,但我无法将其集成到我的代码中:

package com.tesbih;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class Splash extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
     // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.splash);
    Thread timer = new Thread(){

         public void run(){
             try{
                sleep(5000);
            }catch(InterruptedException e){

                e .printStackTrace();

            }finally{

            Intent openStartingPoint = new Intent ("com.tesbih.TESBIHMAINACTIVITY");
            startActivity(openStartingPoint);

            }
        }   
      };

      timer.start();
    }
  }

【问题讨论】:

标签: android eclipse handler splash-screen


【解决方案1】:
public class Splash extends Activity {    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.splash);

        final Intent openStartingPoint = new Intent(this, TESBIHMAINACTIVITY);
        new Handler().postDelayed(new Runnable(){
            @Override
            public void run() {
                startActivity(openStartingPoint);
                finish();
            }
        }, 5000);
    }
}

【讨论】:

    猜你喜欢
    • 2015-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-22
    • 1970-01-01
    • 1970-01-01
    • 2021-09-21
    • 2014-10-11
    相关资源
    最近更新 更多