Activity transition black screen - android

So I've got WelcomeActivity -> HomeActivity and closing WelcomeActivity with finish()/supportFinishAfterTransition(). I want to do either a slideTransition or a fadeTransition (open to other suggestions btw).
I've researched this and as it turns out there are 2+ ways of doing it: either with overridePendingTransition which uses anim.xml files or with Transitions (from the android docs) which use transition.xml files...
I've tried both and both give me unwanted results:
for anims: I get this ugly mid transition black screen:
fade_in.xml:
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="300" />
fade_out.xml:
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:zAdjustment="top"
android:duration="300" />
WelcomeActivity: (I've tried having finish before the overridePendingTransaction)
startActivity(Intent(this, HomeActivity::class.java))
overridePendingTransition(R.anim.fade_in, R.anim.fade_out)
finish()
for transitions: I can't make it so WelcomeActivity closes properly: It either closes before the animation starts or not closing at all. I'm following the android docs.. I've also tried this:
style.xml
<item name="android:windowActivityTransitions">true</item>
<item name="android:windowEnterTransition">#transition/enter_fade</item>
<item name="android:windowExitTransition">#transition/exit_fade</item>
My other questions is which approach should I have? Is Google pushing the transitions over the anims for starting new activities?

What I always do is to start an activity(any way you want, ways are listed here).
I use slide transitions using these two files:
slide_out_left.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="#android:integer/config_mediumAnimTime"
android:fromXDelta="0"
android:toXDelta="-100%p" />
</set>
slide_in_right.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="#android:integer/config_mediumAnimTime"
android:fromXDelta="100%p"
android:toXDelta="0" />
</set>
Then I start an activity like this(this is java):
startActivity(MainActivity.this, SecondActivity.class);
overridePendingTransition(R.anim.slide_in_right.xml, R.anim.slide_in_left.xml);
finish();
Using this, the activity exits giving way to the new one smoothly from right to left.
For the black screen, set the theme of that activity as translucent in the AndroidManifest.xml file
android:theme="#android:style/Theme.Translucent"
so your code will be something like this
<activity android:name=".Activity"
android:theme="#android:style/Theme.Translucent" />
Answer for the black screen taken from: https://stackoverflow.com/a/6468734/9819031

Related

Transitions between two Android activities not behaving as expected

I have some transitions set up between two activities, ActivityA and ActivityB, but they don't behave as expected. The Android API is 22 (5.0 Lollipop). A slow transition between activities is used because both activities have webviews that take a few seconds for their layouts to stabilize.
ActivityA is a NativeActivity and has two methods for switching between activities that are invoked from C++ code.
class ActivityA extends NativeActivity
{
...
protected void startActivityA()
{
startActivity(getApplicationContext(), ActivityA.class);
overridePendingTransitions(R.anim.slow_fade_in, R.anim.slow_fade_out);
}
protected void startActivityB()
{
startActivity(getApplicationContext(), ActivityB.class);
overridePendingTransitions(R.anim.slow_fade_in, R.anim.slow_fade_out);
}
...
}
ActivityB is an Activity.
The res/anim/show_fade_in.xml transition is:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:interpolator="#android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0"
android:factor="1.0"
android:fillAfter="true"
android:fillBefore="true" android:fillEnabled="true"
android:duration="5000" />
</set>
The res/anim/slow_fade_out.xml transition is:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:interpolator="#android:anim/decelerate_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.0"
android:factor="1.0"
android:fillAfter="true"
android:fillBefore="true" android:fillEnabled="true"
android:duration="5000" />
</set>
When ActivityA.startActivityB() is invoked from C++ code, I notice two things happen:
A slow fade to light gray of ActivityA.
The sudden appearance of the stabilized ActivityB webview.
I don't understand why #2 is a sudden appearance and not a slow fade.
When ActivityA.startActivityA() is invoked from C++ code, all I see is a quick cross-fade from ActivityB to ActivityA. I don't understand why I get a quick cross-fade instead of the programmed slow fades.
Why might I not be getting the results I expect?

Make the navigation bar stay on top of any activity animation

First of all I'm working with the Android-L preview. Now, For anyone to not to misunderstand what navigation bar is, here's a pic of it:
https://imageshack.com/i/f0bjjDnQp
I'm applying the activity animation that follows:
activity.startActivity(intent);
activity.overridePendingTransition(R.anim.slide_in_from_bottom, R.anim.scale_in);
Where R.anim.slide_in_from_bottom.xml is:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="100%"
android:toYDelta="0%"/>
</set>
and R.anim.scale_in is:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration="300"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.9"
android:toYScale="0.9"/>
<alpha
android:duration="300"
android:fromAlpha="1.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:toAlpha="0.1"/>
</set>
The animation works fine except for the fact that the new activity does the animation on top of the navigation bar, I'd like it to be the opposite. Also I can see the black status bar during the whole animation which I would like to avoid too.
UPDATE:
So I found what the problem is. With the introduction of Android L preview we have the option to set this Material theme, and that theme makes the animations between activities this way. If I set android:Theme.Holo.Light for instance, everything works fine. As soon as I add this Material theme I got this ugly effect of overlaying the Navigation Bar.
So I thought I could try to find the right parameter in the Material Theme to make it behave as the old theme but I can't manage to figure it out. I've tried setting this line below, but it doesn't work either.
<item name="android:windowActionBarOverlay" >false</item>

Animate the activity entry

I need to start an activity in an animated way..can anyone help me?
Creating an intent and starting an activity in normal way will show new activity.I need to start it from one side,say left side..how to animate it near creating intent..
Use the following:
this.overridePendingTransition(R.anim.slidein_left, R.anim.slideout_right);
Where R.anim.* are Animation XML files in your /res/anim/ folder.
The following is an example of my slidein_left:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromXDelta="-100%"
android:toXDelta="0%" />
</set>
And slideout_right:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromXDelta="0%"
android:toXDelta="100%" />
</set>
What this will do is slide both activities to the left, making the new activity slide in from the left, pushing the old activity out to the right.
Also, as stated by #njzk2, please attempt to make an effort yourself before asking questions, and provide us with things that you may have already tried.

Android fade in , fade out animation issue

I'm trying to customize the animation between two activities by fading out the splashscreen and fading in the main activity.
I trying two solutions, one with fade_in.xml and fade_out.xml where controlling alphas (0-1 , 1-0) and calling everything with overridePendingTransaction(fade_in, fade_out) and one with fade and hold like ni api demo (api/app/animation/fade);
The main problem is that the splashscreen (first animation ) is losing its alpha while sliding to the right as well and the second activity is appearing as wanted.
How is possible to lock the splashscreen to its original position and just making it fading out?
fade
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="#android:integer/config_longAnimTime" />
hold
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator"
android:fromXDelta="0" android:toXDelta="0"
android:duration="#android:integer/config_longAnimTime" />
overridePendingTransition(R.anim.fade, R.anim.hold);
You can use the callback for .fadeOut().

Android transition not working on phone

I created some transitions between activities that are working fine in the emulator, but nothing of them can be seen on the phone (neither fade in-out nor slide). The new activity simply appears like I have not implemented any transitions. Why is that?
fadein.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="1000" />
fadeout.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="1000" />
And i set in the appropriate activity
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
Make sure that animations are enabled on device. For this go to Settings->Display->Animations and select "All Animations".
Enable the transition animation
Settings -> Developer Options -> Transition Animation Scale -> 1x
Go to Settigs then developer options and check for the options that are related to animation and assure that each one of animation option is switched on

Categories

Resources