title: View is shown instantly even though I use handler.postDelayed
body: <p>I have a two RelativeLayout where I have set their visibility to gone using, </p>
  
  <pre><code>android:visibility="gone"
  </code></pre>
  
  <p>And then on the root element of the activity which is also a RelativeLayout, I have added this attribute </p>
  
  <pre><code>android:animateLayoutChanges="true"
  </code></pre>
  
  <p>Here's my activity java code</p>
  
  <pre><code>RelativeLayout rellay1, rellay2;
  Handler handler = new Handler();
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_login);
  
      rellay1 = findViewById(R.id.rellay1);
      rellay2 = findViewById(R.id.rellay2);
  
      handler.postDelayed(new Runnable() {
          @Override
          public void run() {
              rellay1.setVisibility(View.VISIBLE);
              rellay2.setVisibility(View.VISIBLE);
          }
      }, 2000);
  
  }
  </code></pre>
  
  <p>When I run the app, the views get displayed immediately without any wait. If I increase the time to 5s, still same results.</p>
  
  <p>I've looked at the logs when starting the activity and nothing suspicious.</p>
  
  <p><strong>NOTE</strong></p>
  
  <p>When answering questions on SO, I sometimes find it hard to understand the users problem when it's cluttered with XML, so I tried hard to keep my question clean. But that might not be enough to diagnose what's wrong with my code so I'm adding a minimal version of the xml for the parent and two child RelativeLayouts without their contents, just the attributes. If more detail is needed I'd be happy to provide.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:animateLayoutChanges="true"
      android:background="@drawable/grad_bg"
      tools:context=".LoginActivity"&gt;
  
      &lt;RelativeLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerInParent="true"
          android:layout_marginRight="40dp"
          android:layout_marginLeft="40dp"&gt;
  
          &lt;ImageView
              android:id="@+id/img_view_logo"
              android:layout_width="80dp"
              android:layout_height="80dp"
              android:src="@drawable/ic_android_black_24dp"
              android:adjustViewBounds="true"
              android:scaleType="fitCenter"/&gt;
  
          &lt;RelativeLayout
              android:id="@+id/rellay1"
              android:layout_below="@+id/img_view_logo"
              android:layout_width="wrap_content"
              android:visibility="gone"
              android:layout_height="wrap_content"&gt;
  
          &lt;/RelativeLayout&gt;
      &lt;/RelativeLayout&gt;
  
      &lt;RelativeLayout
          android:id="@+id/rellay2"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginLeft="20dp"
          android:layout_marginRight="20dp"
          android:visibility="gone"
          android:layout_alignParentBottom="true"&gt;
  
  
      &lt;/RelativeLayout&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>From the XML above, you'll see that my intention is to have only the ImageView visible initially and the rest should become visible after 2s. </p>
  
  <p>I have looked similar questions about Handler@postDelayed but the problems are not exactly like mine so the solutions where not applicable.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>The only problem here seems to be my lack of proper understanding of the android lifecycle(I'm a beginner here). I carried out an experiment by killing all running apps and tried launching my app again and I saw the animation. </p>
  
  <p>So I guess what was happening here was that, the view had already been created and since my activity was still alive even though I had exited the app, subsequent launches of the App loaded a previously saved instance of the activity and that is why it seemed as if the animation wasn't working.</p>