-2

I have an Android program that includes splash activity. when I run the program everything working perfectly but when press the back button I see my splash activity again .to be able to avoid this it seems I need to close my splash but I can't here is my code

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();
  }
 }
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    have you looked at the docs http://developer.android.com/reference/android/app/Activity.html#finish() – Raghunandan Feb 24 '14 at 19:04
  • Is your splash screen the launcher activity for you app, or is it started from the launch activity? It looks like the former, in which case your current activity is the parent/backstack activity for your main activity. You should clear the back stack in the intent: http://stackoverflow.com/questions/5794506/android-clear-the-back-stack. – user1676075 Feb 24 '14 at 19:35

2 Answers2

2

Add a TimerTask to your code.

@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);
}
aisflat439
  • 936
  • 1
  • 9
  • 26
0

Call finish() to finish your Splash Activity.

Do like this

Intent openStartingPoint = new Intent ("com.tesbih.TESBIHMAINACTIVITY");
startActivity(openStartingPoint);
finish();
Ajay S
  • 48,003
  • 27
  • 91
  • 111
  • @MehmetHikmet It should work, can you let me know how are you calling, paste your new code in the question which you have now and paste the error message if you have any – Ajay S Feb 24 '14 at 19:20