我有一个包含启动活动的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)
在代码中添加TimerTask。
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
TimerTask splash = new TimerTask(){
public void run() {
onDestroy();
startActivity(new Intent(Splash.this, MainActivity.class));
}
};
Timer splashScreenTimer = new Timer();
// Timer set to 4.5 seconds
splashScreenTimer.schedule(splash, 5000);
}
答案 1 :(得分:-1)
致电finish()
完成您的启动活动。
这样做
Intent openStartingPoint = new Intent ("com.tesbih.TESBIHMAINACTIVITY");
startActivity(openStartingPoint);
finish();