2014-03-27 6 views
0

앱을 실행하면 SplashScreen이 화면에서 몇 초 동안 깜박이고 3 초 동안 완전히 사라집니다. 3 초를 마친 후 MainActivity가 시작됩니다. 질문 : 화면이 꺼지지 않고 스플래시 화면을 표시하는 방법은 무엇입니까?스플래시 화면이 안드로이드에 표시되지 않음

public class SplashScreen extends Activity { 
private static int SPLASH_TIME_OUT = 3000; 

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

    new Handler().postDelayed(new Runnable() { 

     @Override 
     public void run() { 
      startActivity(new Intent(SplashScreen.this, MainActivity.class)); 

     } 
    }, SPLASH_TIME_OUT); 
    SplashScreen.this.finish(); 
} 

@Override 
public void onBackPressed() { 
    SplashScreen.this.finish(); 
    super.onBackPressed(); 
}} 

매니페스트 파일

<application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity android:name="com.simbotix.guardianonthego.SplashScreen" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name="com.simbotix.guardianonthego.MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
     </activity> 
    </application> 

답변

2

변경이

new Handler().postDelayed(new Runnable() { 

     @Override 
     public void run() { 
      startActivity(new Intent(SplashScreen.this, MainActivity.class)); 

     } 
    }, SPLASH_TIME_OUT); 
    SplashScreen.this.finish(); 

onBackPressed

에서 작업을 완료 할 필요 또한
new Handler().postDelayed(new Runnable() { 

     @Override 
     public void run() { 
      startActivity(new Intent(SplashScreen.this, MainActivity.class)); 
       SplashScreen.this.finish(); 
     } 
    }, SPLASH_TIME_OUT); 

에 15,
@Override 
public void onBackPressed() { 
    SplashScreen.this.finish(); // Remove this 
    super.onBackPressed(); 
} 
+0

해야하는 이유는, 같은 내가 설명해 주시겠습니까? {SplashScreen.this.finish(); // Remove this} – Shiva

+1

누를 때 활동이 자동으로 끝나고 onDestroy 메소드가 호출됩니다. – Sunny

+0

SplashScreen.java에 onDestroy 메소드를 포함시켜야합니까? – Shiva

1
 new Handler().postDelayed(new Runnable() {  
     @Override 
     public void run() { 
      startActivity(new Intent(SplashScreen.this, MainActivity.class)); 
      SplashScreen.this.finish(); 

     } 
    }, SPLASH_TIME_OUT); 

SplashScreen.this.finish(); 코드 행이 SplashActivity를 완료하고 3 초 후에 실행해야하므로 처리기 스레드에 있고 3 초 후에 실행됩니다.

0

MainActivity을 시작하기 전에 SplashScreen을 완료하지 마십시오. SplashScreen 클래스에서 SplashScreen.this.finish(); 행을 삭제하면됩니다. 대신

0
public void run() { 
       startActivity(new Intent(SplashScreen.this, MainActivity.class)); 
       finish() 
      } 
}, SPLASH_TIME_OUT); 

public void run() { 
      startActivity(new Intent(SplashScreen.this, MainActivity.class)); 

     } 
    }, SPLASH_TIME_OUT); 
    SplashScreen.this.finish(); 
0

빠른 수정 :

제거

SplashScreen.this.finish(); 

변경

public void run() { 
     startActivity(new Intent(SplashScreen.this, MainActivity.class)); 
     finish(); 
    } 
관련 문제