2

I'd like to know how to set a loading animation before the first activity starts. Currently, when my first activity begins there is a black screen, I'd like to replace it by an animation. Is that possible to do that ?

Kevin Vincent
  • 587
  • 13
  • 28

2 Answers2

1

If black screen is your problem, try to make the activity as transparent. Refer this link: How do I create a transparent Activity on Android?

If you want to animation activity transition, use the follow:

startActivity(intent);
overridePendingTransition(R.anim.enter_anim, R.anim.exit_anim);

Where, enter_anim and exit_anim are animations defined in XML

Community
  • 1
  • 1
Mr.Rao
  • 321
  • 2
  • 6
-2

If you want to add a logo splash is good way. Check this out, Its a SplashScreen activity which will be visible for 3 secs, and then will enter your main screen. More here

    public class SplashScreen extends Activity {

    // Splash screen timer
    private static int SPLASH_TIME_OUT = 3000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

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

            /*
             * Showing splash screen with a timer. This will be useful when you
             * want to show case your app logo / company
             */

            @Override
            public void run() {
                // This method will be executed once the timer is over
                // Start your app main activity
                Intent i = new Intent(SplashScreen.this, MainActivity.class);
                startActivity(i);

                // close this activity
                finish();
            }
        }, SPLASH_TIME_OUT);
    }

}
W4R10CK
  • 5,502
  • 2
  • 19
  • 30
  • Ok good ! I will try that and give you a feedback later. Thanks ! – Kevin Vincent Sep 19 '16 at 08:49
  • This is bad practice, use `windowBackground` instead: https://developer.android.com/topic/performance/vitals/launch-time#themed – Philio Mar 25 '19 at 14:16
  • @Philio, As you can see this answer is pretty old from '16 and I believe this answer is correct according to time when it was asked. Kindly do not downvote. – W4R10CK May 09 '19 at 06:00