質問

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();
  }
 }
役に立ちましたか?

解決

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

他のヒント

Call finish() to finish your Splash Activity.

Do like this

Intent openStartingPoint = new Intent ("com.tesbih.TESBIHMAINACTIVITY");
startActivity(openStartingPoint);
finish();
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top