4

In my android application, I have a splash screen which blinks the logo of the app for 3 seconds and then start the login activity. Here is my code:

imgView.postDelayed(new Runnable() {
        @Override
        public void run() {
            final Animation animation = new AlphaAnimation(1, 0);
            animation.setDuration(1000);
            animation.setInterpolator(new LinearInterpolator());
            animation.setRepeatCount(Animation.INFINITE);
            animation.setRepeatMode(Animation.REVERSE);
            imgView.startAnimation(animation);
        }
    }, 3000);
Intent intent = new Intent(SplashscreenActivity.this,LoginActivity.class);
startActivity(intent);

But the image blinks infinitely. How to stop blinking after 3 seconds? I referred some posts but I could not get an exact answer.

Lak
  • 381
  • 1
  • 5
  • 23
  • 2
    I think it's because of the `setRepeatCount(Animation.INFINITE)` line. Check [Animation.setRepeatCount](http://developer.android.com/reference/android/view/animation/Animation.html#setRepeatCount(int)) description. – AL. Mar 17 '16 at 05:24
  • Have you tried changing it to a certain value? – AL. Mar 17 '16 at 05:26
  • Also a simplistic `BlinkerView` could do the trick - see my answer here: https://stackoverflow.com/a/50299715/2102748 - the only thing to take care of is to stop blinking on your own. That you can do by posting a message to the handler, like others suggested. – milosmns May 11 '18 at 20:23

3 Answers3

6

You can try this

      final Animation animation = new AlphaAnimation(1, 0);
      animation.setDuration(1000);
      animation.setInterpolator(new LinearInterpolator());
      animation.setRepeatCount(Animation.INFINITE);
      animation.setRepeatMode(Animation.REVERSE);
      imgView.startAnimation(animation);

      new Handler().postDelayed(new Runnable() {
          @Override
          public void run() {
              animation .cancel();
              Intent intent = new Intent(SplashscreenActivity.this, LoginActivity.class);
              startActivity(intent);

          }
      }, 3000);

You can use imgView.clearAnimation() instead of animation.cancel();

I hope this will help you. thanks

rockstar
  • 587
  • 4
  • 22
0

Try

animation.setRepeatCount(1);

instead of

animation.setRepeatCount(Animation.INFINITE);
Viral Patel
  • 32,418
  • 18
  • 82
  • 110
GIRIDHARAN
  • 169
  • 1
  • 1
  • 14
0

Replace below line

animation.setRepeatCount(Animation.INFINITE);

with this in your code

 animation.setRepeatCount(1);
Meenal
  • 2,879
  • 5
  • 19
  • 43