title: How to pause and resume animation in onPause() and onResume() in android?
body: <p>I have an activity which has 16 animated buttons .Initially they are invisible.
  After that I am using a for loop each button is undergoing a fade animation . The <strong>R.anim.fade</strong> xml file is present at <strong>@anim/fade</strong>. </p>
  
  <p>The problem is I cant pause and resume them. I like to pause and resume them in <strong>onPause()</strong> and <strong>onResume()</strong> method of an activity.   </p>
  
  <p><strong>Also is there a method to check if all animations are complete??</strong>. That is how to know that <strong>b16 button</strong> which is the last button has completed its animation??</p>
  
  <p>Here is my java code.</p>
  
  <pre><code>package com.ash432.itguesses;
  
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.view.animation.Animation;
  import android.view.animation.AnimationUtils;
  import android.widget.Button;
  
   public class hints extends AppCompatActivity
   {
  
  private int button_arr[] = {R.id.b1, R.id.b2, R.id.b3, R.id.b4, R.id.b5, 
  R.id.b6, R.id.b7, R.id.b8, R.id.b9,
  R.id.b10, R.id.b11, R.id.b12, R.id.b13, R.id.b14, R.id.b15, R.id.b16};
  
  Animation anim;
  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_hints);
      int i;
      for (i = 0; i &lt; 16; i++)
          invisible(button_arr[i]);
  
  
     for(i=0;i&lt;16;i++)
              anim_button(button_arr[i], 200 * (i + 1));
  
      }
  
  
  private void invisible(int id)
  {
      Button b = (Button) findViewById(id);
      b.setVisibility(View.INVISIBLE);
  }
  
  private void anim_button(int id, long duration)
  {
      Button b = (Button) findViewById(id);
      anim = AnimationUtils.loadAnimation(this, R.anim.fade);
      anim.setStartOffset(duration);
      b.startAnimation(anim);
      b.setVisibility(View.VISIBLE);
  }
  
  @Override
  protected void onResume()
  {
     super.onResume();
  }
  
  @Override
  protected void onPause()
  {
      super.onPause();
  }
  } 
  </code></pre>
  
  <p>Here is my xml file </p>
  
  <pre><code>  &lt;?xml version="1.0" encoding="utf-8"?&gt;
    &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:background="#040404"
              android:clickable="false"
              android:orientation="vertical"
              android:id="@+id/rel"&gt;
  
      &lt;Button
      android:id="@+id/b1"
  
      android:textColor="#000000"
      android:textSize="35sp"
  
      android:layout_width="55dp"
      android:layout_height="55dp"
      android:background="#FFFFFF"
      android:shadowColor="#252323"
      android:shadowDx="0"
      android:shadowDy="0"
      android:shadowRadius="5"
      android:layout_marginTop="19dp"
      android:gravity="center"
      android:layout_marginLeft="24dp"
      android:layout_marginStart="24dp"
      android:focusable="false"
      android:focusableInTouchMode="false"
  
      android:layout_alignParentLeft="true"
      android:layout_alignParentStart="true" /&gt;
  
  &lt;Button
      android:id="@+id/b2"
      android:textColor="#000000"
      android:textSize="35sp"
      android:layout_width="55dp"
      android:layout_height="55dp"
      android:background="#FFFFFF"
      android:shadowColor="#A8A8A8"
      android:shadowDx="0"
      android:shadowDy="0"
      android:shadowRadius="5"
      android:layout_marginLeft="17dp"
      android:layout_marginStart="16dp"
      android:layout_alignTop="@+id/b1"
      android:layout_toRightOf="@+id/b1"
      android:layout_toEndOf="@+id/b1"
      android:gravity="center" /&gt;
  
  &lt;Button
      android:id="@+id/b3"
      android:textColor="#000000"
      android:textSize="35sp"
      android:layout_width="55dp"
      android:layout_height="55dp"
      android:background="#FFFFFF"
      android:shadowColor="#A8A8A8"
      android:shadowDx="0"
      android:shadowDy="0"
      android:shadowRadius="5"
      android:layout_marginLeft="17dp"
      android:layout_marginStart="15dp"
      android:layout_alignTop="@+id/b2"
      android:layout_toRightOf="@+id/b2"
      android:layout_toEndOf="@+id/b2"
      android:gravity="center" /&gt;
  
  &lt;Button
      android:id="@+id/b4"
      android:textColor="#000000"
      android:textSize="35sp"
      android:layout_width="55dp"
      android:layout_height="55dp"
      android:background="#FFFFFF"
      android:shadowColor="#A8A8A8"
      android:shadowDx="0"
      android:shadowDy="0"
      android:shadowRadius="5"
      android:layout_marginLeft="17dp"
      android:layout_marginStart="17dp"
      android:layout_alignTop="@+id/b3"
      android:layout_toRightOf="@+id/b3"
      android:layout_toEndOf="@+id/b3"
      android:gravity="center" /&gt;
  
  &lt;Button
      android:id="@+id/b5"
      android:textColor="#000000"
      android:textSize="35sp"
      android:layout_width="55dp"
      android:layout_height="55dp"
      android:background="#FFFFFF"
      android:shadowColor="#A8A8A8"
      android:shadowDx="0"
      android:shadowDy="0"
      android:shadowRadius="5"
      android:layout_marginTop="12dp"
      android:layout_below="@+id/b1"
      android:layout_alignLeft="@+id/b1"
      android:layout_alignStart="@+id/b1"
      android:gravity="center" /&gt;
  
  &lt;Button
      android:id="@+id/b6"
      android:textColor="#000000"
      android:textSize="35sp"
      android:layout_width="55dp"
      android:layout_height="55dp"
      android:background="#FFFFFF"
      android:shadowColor="#A8A8A8"
      android:shadowDx="0"
      android:shadowDy="0"
      android:shadowRadius="5"
      android:layout_alignTop="@+id/b5"
      android:layout_alignLeft="@+id/b2"
      android:layout_alignStart="@+id/b2"
      android:gravity="center" /&gt;
  
  &lt;Button
      android:id="@+id/b7"
      android:textColor="#000000"
      android:textSize="35sp"
      android:layout_width="55dp"
      android:layout_height="55dp"
      android:background="#FFFFFF"
      android:shadowColor="#A8A8A8"
      android:shadowDx="0"
      android:shadowDy="0"
      android:shadowRadius="5"
      android:layout_alignTop="@+id/b6"
      android:layout_alignLeft="@+id/b3"
      android:layout_alignStart="@+id/b3"
      android:gravity="center" /&gt;
  
  &lt;Button
      android:id="@+id/b8"
      android:textColor="#000000"
      android:textSize="35sp"
      android:layout_width="55dp"
      android:layout_height="55dp"
      android:background="#FFFFFF"
      android:shadowColor="#A8A8A8"
      android:shadowDx="0"
      android:shadowDy="0"
      android:shadowRadius="5"
      android:layout_alignTop="@+id/b7"
      android:layout_alignLeft="@+id/b4"
      android:layout_alignStart="@+id/b4"
      android:gravity="center" /&gt;
  
  &lt;Button
      android:id="@+id/b9"
      android:textColor="#000000"
      android:textSize="35sp"
      android:layout_width="55dp"
      android:layout_height="55dp"
      android:background="#FFFFFF"
      android:shadowColor="#A8A8A8"
      android:shadowDx="0"
      android:shadowDy="0"
      android:shadowRadius="5"
      android:layout_marginTop="12dp"
      android:layout_below="@+id/b5"
      android:layout_alignLeft="@+id/b5"
      android:layout_alignStart="@+id/b5"
      android:gravity="center" /&gt;
  
  &lt;Button
      android:id="@+id/b10"
      android:textColor="#000000"
      android:textSize="35sp"
      android:layout_width="55dp"
      android:layout_height="55dp"
      android:background="#FFFFFF"
      android:shadowColor="#A8A8A8"
      android:shadowDx="0"
      android:shadowDy="0"
      android:shadowRadius="5"
      android:layout_alignTop="@+id/b9"
      android:layout_alignLeft="@+id/b6"
      android:layout_alignStart="@+id/b6"
      android:gravity="center" /&gt;
  
  &lt;Button
      android:id="@+id/b11"
      android:textColor="#000000"
      android:textSize="35sp"
      android:layout_width="55dp"
      android:layout_height="55dp"
      android:background="#FFFFFF"
      android:shadowColor="#A8A8A8"
      android:shadowDx="0"
      android:shadowDy="0"
      android:shadowRadius="5"
      android:layout_alignTop="@+id/b10"
      android:layout_alignLeft="@+id/b7"
      android:layout_alignStart="@+id/b7"
      android:gravity="center" /&gt;
  
  &lt;Button
      android:id="@+id/b12"
      android:textColor="#000000"
      android:textSize="35sp"
      android:layout_width="55dp"
      android:layout_height="55dp"
      android:background="#FFFFFF"
      android:shadowColor="#A8A8A8"
      android:shadowDx="0"
      android:shadowDy="0"
      android:shadowRadius="5"
      android:layout_alignTop="@+id/b11"
      android:layout_alignLeft="@+id/b8"
      android:layout_alignStart="@+id/b8"
      android:gravity="center" /&gt;
  
  &lt;Button
      android:id="@+id/b13"
      android:textColor="#000000"
      android:textSize="35sp"
      android:layout_width="55dp"
      android:layout_height="55dp"
      android:background="#FFFFFF"
      android:shadowColor="#A8A8A8"
      android:shadowDx="0"
      android:shadowDy="0"
      android:shadowRadius="5"
      android:layout_marginTop="12dp"
      android:layout_below="@+id/b9"
      android:layout_alignLeft="@+id/b9"
      android:layout_alignStart="@+id/b9"
      android:gravity="center" /&gt;
  
  &lt;Button
      android:id="@+id/b14"
      android:textColor="#000000"
      android:textSize="35sp"
      android:layout_width="55dp"
      android:layout_height="55dp"
      android:background="#FFFFFF"
      android:shadowColor="#A8A8A8"
      android:shadowDx="0"
      android:shadowDy="0"
      android:shadowRadius="5"
      android:layout_alignTop="@+id/b13"
      android:layout_alignLeft="@+id/b10"
      android:layout_alignStart="@+id/b10"
      android:gravity="center" /&gt;
  
  &lt;Button
      android:id="@+id/b15"
      android:textColor="#000000"
      android:textSize="35sp"
      android:layout_width="55dp"
      android:layout_height="55dp"
      android:background="#FFFFFF"
      android:shadowColor="#A8A8A8"
      android:shadowDx="0"
      android:shadowDy="0"
      android:shadowRadius="5"
      android:layout_alignTop="@+id/b14"
      android:layout_alignLeft="@+id/b11"
      android:layout_alignStart="@+id/b11"
      android:gravity="center"
      android:singleLine="false"
      android:longClickable="false" /&gt;
  
  &lt;Button
      android:id="@+id/b16"
      android:textColor="#000000"
      android:textSize="35sp"
      android:layout_width="55dp"
      android:layout_height="55dp"
      android:background="#FFFFFF"
      android:shadowColor="#A8A8A8"
      android:shadowDx="0"
      android:shadowDy="0"
      android:shadowRadius="5"
      android:layout_alignTop="@+id/b15"
      android:layout_alignLeft="@+id/b12"
      android:layout_alignStart="@+id/b12"
      android:gravity="center" /&gt;
  
  
     &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>This is my <strong>R.anim.fade</strong> xml file . Actually I am trying to do <strong>blink</strong> animation.</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
   &lt;set xmlns:android="http://schemas.android.com/apk/res/android"
   android:interpolator="@android:anim/accelerate_interpolator"
   &gt;
   &lt;alpha
      android:fromAlpha="0.0"
      android:toAlpha="1.0"
      android:duration="200"
  /&gt;
  &lt;alpha
      android:fromAlpha="1.0"
      android:toAlpha="0.0"
      android:duration="200"
  /&gt;
  &lt;/set&gt;
  </code></pre>