I'm developing a chat app and am having trouble with figuring out how to get the transition between two activities to animate correctly. I have googled this for a while now and have also searched SO for it, but sorry in advance if this question has already been answered.
I have a ChatMainActivity
, which holds a Fragment containing a list of chats and a ChatContentFragmentActivity
, which holds a Fragment containing the chat messages. As seen below I have declared the ChatMainActivity as launchMode="singleTask"
in my AndroidManifest.xml.
<activity
android:name=".ui.activities.ChatMainActivity"
android:launchMode="singleTask"
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustResize" />
<activity
android:name=".ui.activities.ChatContentFragmentActivity"
android:parentActivityName=".ui.activities.ChatMainActivity"
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustResize" />
These are my animation .xmls:
chat_content_activity_enter_animation.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@integer/activity_animation_duration"
android:fromXDelta="100%"
android:interpolator="@android:anim/decelerate_interpolator"
android:toXDelta="0" />
</set>
chat_content_activity_exit_animation.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@integer/activity_animation_duration"
android:fromXDelta="0"
android:interpolator="@android:anim/decelerate_interpolator"
android:toXDelta="100%" />
</set>
chat_list_activity_enter_animation.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@integer/activity_animation_duration"
android:fromXDelta="-100%"
android:interpolator="@android:anim/decelerate_interpolator"
android:toXDelta="0" />
</set>
chat_list_activity_exit_animation.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@integer/activity_animation_duration"
android:fromXDelta="0"
android:interpolator="@android:anim/decelerate_interpolator"
android:toXDelta="-100%" />
</set>
And here is how I use them:
In the Adapter
of the RecyclerView
containing the chats in ChatMainActivity
Intent intent = new Intent(context, ChatContentFragmentActivity.class);
context.startActivity(intent);
activity.overridePendingTransition(R.anim.chat_content_activity_enter_animation, R.anim.chat_list_activity_exit_animation);
ChatContentFragmentActivity
@Override
public void finish() {
super.finish();
overridePendingTransition(R.anim.chat_content_activity_exit_animation, R.anim.chat_list_activity_enter_animation);
}
My Problem now is that the enter and exit animations of the ChatContentFragmentActivity
are shown, but the ChatMainActivity
does nothing.
There was a SO question that I can't seem to find now, that suggested, that singleTask was a problem here, but I remember the solution suggest in that question not helping me.
Does anyone know how I can get the exit and enter animation of my ChatMainActivity
to play?