JarsOfJam-Scheduler
JarsOfJam-Scheduler

Reputation: 3149

How to execute my overridePendingTransition?

NB: similar questions are listed at the end of this topic, and you will see I have taken into account their answers and their comments... However nothing works.


I am developing a splash screen for my Android application. This splash screen is in the main activity, and fades out. When it finishes fading, the main activity starts another activity.

The problem

The problem is that the main activity starts the other one without showing the fading effect.

Configuration

Emulator

The emulator uses an AVD cofigured like this: the API level is 27, Android is 8.1 Oreo.

build.gradle (Module: app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.."
        minSdkVersion 27
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        renderscriptTargetApi 27
        renderscriptSupportModeEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

What i have written to do this fading

I... :

  1. Created MainActivity.java and put the startActivity and overridePendingTransition calls inside

  2. Created two themes in AndroidManifest.xml (one for the main activity, another for the other one). I set windowActivityTransitions to true in the app's theme.

  3. Created a style in anim/fade_out_home_activity.xml for the animation (thus for the main activity).

  4. Created the other activity (including the new .java, new .xml and an update of the manifest).

What I have done, in detail

MainActivity.java

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    startActivity(new Intent(this, HomeActivity.class), ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
    finish();
    overridePendingTransition(R.anim.fade_out_home_activity, R.anim.fade_out_home_activity);
    setContentView(R.layout.activity_main);
}

}

anim/fade_out_home_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:interpolator/decelerate_quad"
    android:fromAlpha="1.0" android:toAlpha="0.0"
    android:duration="@android:integer/config_longAnimTime"/>

(probably not useful for help) styles.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <item name="android:windowActivityTransitions">true</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

My question

Do you know why the animation isn't shown (note that maybe it's executed - or not)?

Similar questions

I already created several topics on how to realize a splash screen animation. Note that I don't want to use setEnterTransition etc. (Why the XML specified transition isn't executed? (or why its specified duration isn't taken account?) , the reason is in my (my!) first comment in OP here How to fade out an Activity's UI, and fade in another Activity's UI? ).

I followed some answers from here: overridePendingTransition not working . Those are taken into account in the above code.

I also added ActivityOptions.makeSceneTransitionAnimation(this).toBundle() as suggested in an answer here: Android: Activities animations not working .

Nothing works, I'm going crazy so much I wasted time doing a simple animation between two activities! At the beginning, I also wanted to execute another animation, when the main activity is started, but I gave up the idea (someone told me it was impossible - you can retrieve this answer or comment in the above links).

Upvotes: 0

Views: 1004

Answers (1)

Aksh
Aksh

Reputation: 323

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


new CountDownTimer(5000, 1000) {

    public void onTick(long millisUntilFinished) {

    }
    public void onFinish() {
        startActivity(new Intent(MainActivity.this, HomeActivity.class), 
        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
    }

}.start();

}

Upvotes: 1

Related Questions