LocalActivityManager destroyActivity with animation
-
09-12-2019 - |
Question
I wanna add animation effect when a activity call back method.And I use activityGroup to implement activitymanger and use LocalActivityManager to start and back any activity.
when start an activity add the animation use the follow code
public static void startActivity(Intent intent, String id) {
View view = mLocalActivityManager.startActivity(id,
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
Animation hyperspaceJump = AnimationUtils.loadAnimation(mActivityGroup,
R.anim.dync_in_from_right);
view.startAnimation(hyperspaceJump);
view.setTag(id);
mPreviousActivityTag = getCurrentActivityTag();
mViewContainer.addView(view);
}
but i don't know how to add the animation effect when an activity return back to the one , which start the cur activity. the back method is like that
public static void removeCurrentActivity() {
String tag = getCurrentActivityTag();
if (com.ct.ipaipai.global.Utily.isStringEmpty(tag) == false) {
int cnt = getActivityCount();
mViewContainer.removeViewAt(cnt - 1);
View view = mLocalActivityManager.destroyActivity(tag, true).getDecorView();
}
}
any one know that?
thanks
Solution
I don't know which ActivityGroup
you are using, but when I used ActivityGroup
sometimes in past, I did something like this
String tag = getCurrentActivityTag();
LocalActivityManager manager = getLocalActivityManager();
Animation animation = null;
animation = AnimationUtils.loadAnimation(this, R.anim.de_rail);
Window oldWindow = manager.getCurrentActivity().getWindow();
if(oldWindow != null)
{
View v =oldWindow.getDecorView();
v.setBackgroundResource(R.drawable.app_pink_background);
v.startAnimation(animation);
}
manager.destroyActivity(tag, true);
// now set old Activity View
Intent lastIntent = manager.getActivity(lastId).getIntent();
Window newWindow = manager.startActivity(lastId, lastIntent);
if(newWindow != null)
{
View view = newWindow.getDecorView();
setContentView(view);
}
where R.anim.de_rail
, which was actually de_rail.xml
was something like this:
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0%p"
android:toXDelta="100%p"
android:duration="400" />
You can find my modified version here. It shows animation on start child Activity
and finishing child Activity
.