目前我正在编写一个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();
}
}
答案 0 :(得分:2)
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);
}
}