문제

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