2012-05-18 7 views
0
public class tryAnimActivity extends Activity 
{ 

    /** 
    * The thread to process splash screen events 
    */ 
    private Thread mSplashThread;  

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    // Splash screen view 
    setContentView(R.layout.janman); 

    final tryAnimActivity sPlashScreen = this; 

    // The thread to wait for splash screen events 
    mSplashThread = new Thread(){ 
     @Override 
     public void run(){ 
      try { 
       synchronized(this){ 
        // Wait given period of time or exit on touch 
        wait(5000); 
       } 
      } 
      catch(InterruptedException ex){      
      } 

      finish(); 

      // Run next activity 
      Intent intent = new Intent(); 
      intent.setClass(sPlashScreen, TabsActivity.class); 
      startActivity(intent); 
      stop();      
     } 
    }; 

    mSplashThread.start();   
    } 

    /** 
    * Processes splash screen touch events 
    */ 
    @Override 
    public boolean onTouchEvent(MotionEvent evt) 
    { 
    if(evt.getAction() == MotionEvent.ACTION_DOWN) 
    { 
     synchronized(mSplashThread){ 
      mSplashThread.notifyAll(); 
     } 
    } 
    return true; 
    }  
} 

이 코드의 문제점은 무엇입니까? 클릭시 충돌이 발생합니다. 또한이 활동이 끝나면 다음 활동이 시작되지 않습니다. 이것은 스플래시 화면을 표시하는 데 사용되는 활동입니다.스플래시 화면이 작동하지 않습니다.

+0

충돌을 표시하는 stacktrace를 게시하십시오. –

답변

1

작동 stop() 방법을 제거합니다. 아래 활동을위한 스플래시 코드가 잘 작동합니다. 도움이되기를 바랍니다.

public class SplashScreenActivity extends Activity implements OnTouchListener { 

    private int SPLASH_DISPLAY_LENGTH = 3000; 

    private Handler splashHandler; 
    private Runnable splashRunnable; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.splash); 

     findViewById(R.id.splash_img).setOnTouchListener(this); 

     splashHandler = new Handler(); 
     splashRunnable = new Runnable() 
     { 
      @Override 
      public void run() 
      { 
       SplashScreenActivity.this.finish(); 
       Intent mainIntent = new Intent(SplashScreenActivity.this, HomeActivity.class); 
       startActivity(mainIntent); 
      } 
     }; 

     splashHandler.postDelayed(splashRunnable, SPLASH_DISPLAY_LENGTH); 

    } 

    @Override 
    public boolean onTouch(View v, MotionEvent event) { 
     if (event.getAction() == MotionEvent.ACTION_DOWN){ 
      splashHandler.removeCallbacks(splashRunnable); 
      SplashScreenActivity.this.finish(); 
      Intent mainIntent = new Intent(SplashScreenActivity.this, HomeActivity.class); 
      startActivity(mainIntent); 
     } 
     return true; 
    } 
} 
1

그냥 내가 스레드 대신의 Runnable 요소를 사용하는 것을 선호

관련 문제