To create a Splash Screen, you need an Activity to launch before your main activity starts.
Let ActivitySplash be the Splash Screen activity and MainActivity be the Main Activity for you app.
Here, you don't have to do anything with your main activity.
Just make sure you have the following 'intent-filter' in your ActivitySplash and not in your MainActivity :
Let ActivitySplash be the Splash Screen activity and MainActivity be the Main Activity for you app.
Here, you don't have to do anything with your main activity.
Just make sure you have the following 'intent-filter' in your ActivitySplash and not in your MainActivity :
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Now in your Splash Activity, create a Runnable and a Handler, and using the handler, delay the runnable by your desire. Following is the code for the ActivitySplash:
public class SplashActivity extends ActionBarActivity {
int Delay_Time = 3000; // in milli seconds;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Handler handler = new Handler();
Runnable runnable = new Runnable() {
@Override
public void run() {
Intent intent = new Intent(SplashActivity.this,
MainActivity.class);
startActivity(intent); // launch the main activity
finish(); // finish this splash activity
}
};
handler.postDelayed(runnable, Delay_Time);
}
}
Comments
Post a Comment