0

Is it possible to automatically trigger scene change in onResume in proper way? I have a layout for the activity:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <include layout="@layout/scene0" />
    </FrameLayout>
</RelativeLayout>

And 2 scenes

scene1:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    <TextView
        android:id="@+id/test_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Sample text"
        android:textSize="20dp"
        android:layout_centerInParent="true"/>
</RelativeLayout>

scene2:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/test_text"
        android:text="Sample text"
        android:textSize="20dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"/>

</RelativeLayout>

The problem is: i can't call TransitionManager.go(scene2) in onResume(), it simply goes to the second scene without animation. But if i post it with Handler and make delay about 100 ms it works.

MightySeal
  • 2,293
  • 2
  • 17
  • 32

1 Answers1

0

For Activity onWindowFocusChanged method can be used. Simply like this:

@Override
public void onWindowFocusChanged(final boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

    if(hasFocus) {
        TransitionManager.go(scene2);
    }
}
MightySeal
  • 2,293
  • 2
  • 17
  • 32