I have an ActivityGroup
meant to develop a tabHost
. One of the tabs contains two activities into it. The problem is that when I move between this two activities there is no sliding between them. The old activity dissappears and the new one comes automatically on screen.
What I need to implement is this - when I move from activity2 back to activity 1, the activity2 has to leave the screen by sliding to the right and the new activity(activity 1) has to come into the screen by sliding from left to right.
The effect is similar to android default style when an intent is used to move between activities!
What I have achieved so far is:
when I try to move from activity 2 to activity 1: activity 2( the old one) dissapears from the screen, the screen turns black and the new activity comes into the screen by sliding from left to right. It would be great if I would manage to make the old activity to leave the screen by sliding too.
This is my code for coming back from the old activity to the new one:
Animation animation = null;
Window oldWindow = manager.getCurrentActivity().getWindow();
if(oldWindow != null)
{
animation = AnimationUtils.loadAnimation(this, R.anim.right_to_left);
View v =oldWindow.getDecorView();
v.startAnimation(animation);
}
manager.destroyActivity(mIdList.get(index), true);
mIdList.remove(index); index--;
String lastId = mIdList.get(index);
lastIntent = manager.getActivity(lastId).getIntent();
newView = manager.startActivity(lastId, lastIntent).getDecorView();
newView.startAnimation(AnimationUtils.loadAnimation(this, R.anim.left_to_right));
if(newView != null)
{
setContentView(newView);
}
One big bug is this: if I remove this line from my code: `setContentView(newView)` I get the desired effect for the old activity. Meaning the old activity leaves the screen by sliding, but the new one never comes in.
If I put that line back the old activity doesn't do any sliding just dissapears!!!!
I use a Samsung Galaxy for testing and I tried to use overridePendingTransition
but it has no effect on the animations.
Here are my xml
files:
right_to_left.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="true">
<translate
android:fromXDelta="0%" android:toXDelta="100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="3500" />
</set>
left_to_right.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="true">
<translate android:fromXDelta="-100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="3500"/>
</set>
Thank you. Hope you can help me.