2014-02-24 44 views
-1

我有一个包含飞溅活动的android程序。当我运行该程序的一切完美的工作,但是当PRES后退按钮我看到我的溅活动再次。要能避免这个,看来我需要关闭我的飞溅,但我可以T 这里是我的代码我想关闭我的飞溅活动

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(); 
    } 





} 
+1

有你看了文档http://developer.android.com/reference/android/app/Activity.html#finish() – Raghunandan

+0

是您的闪屏发射活动为你的应用程序,或者是它从发起活动开始?它看起来像前者,在这种情况下,您当前的活动是您主要活动的父/子堆活动。你应该清理后端堆栈的意图:http://stackoverflow.com/questions/5794506/android-clear-the-back-stack。 – user1676075

回答

1

添加一个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); 
} 
+0

也onDestroy( ); – aisflat439

-1

致电finish()完成您的飞溅活动。

做这样

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

这段代码不行不通 –

+0

@MehmetHikmet它应该工作,你可以让我知道你是怎么打电话,在你现在的问题中粘贴你的新代码,并粘贴错误信息,如果你有任何 –