2013-09-06 4 views
0

SplashScreen 활동에서 스레드를 종료하려면 finish()를 사용하고 Activity2로 이동하기 전에 응용 프로그램을 최소화하면됩니다. 어떻게하면 SplashScreen 활동을 끝내고 finish()를 호출하지 않고 Activity2로 이동하여 앱이 최소화되지 않도록 할 수 있습니까?SplashScreen finish() 응용 프로그램이 최소화 된 후

public class SplashScreen 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.splash); 

     final SplashScreen 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, MainActivity.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; 
    }  
} 

답변

2

전화 마감 startActivity를

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


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



      //call finish after startActivity 
      finish(); 
      //stop();      
     } 
    }; 

    mSplashThread.start();   
1

후 나는 이런 식으로 작업을 수행합니다

private class IntentLauncher extends Thread { 
     @Override 
     /** 
     * Sleep for some time and than start new activity. 
     */ 
     public void run() { 
     try { 
      // Sleeping 
      Thread.sleep(SLEEP_TIME*1000); 
     } catch (Exception e) { 
      Log.e(TAG, e.getMessage()); 
     } 

     // Start main activity 
     Intent intent = new Intent(SplashActivity.this, MainActivity.class); 
     SplashActivity.this.startActivity(intent); 


     SplashActivity.this.finish(); 
     } 
    } 
관련 문제