我有 5 个选项卡。每个选项卡包含多个活动,每个活动包含多个片段。
例如:需要导航在 tab1 - Activity1 - Fragment1_Activity1 - Fragment2_Activity1 - Activity2 - Fragmnet1_Activity2
我使用 ActivityGroup 在选项卡中显示 Activity2。
活动组类:
public class CouponsActivityGroup extends ActivityGroup {
private Stack<String> stack;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (stack == null) stack = new Stack<String>();
//start default activity
push("FirstStackActivity", new Intent(this, CouponsContianer.class));
}
@Override
public void finishFromChild(Activity child) {
pop();
}
@Override
public void onBackPressed() {
pop();
}
public void push(String id, Intent intent) {
Window window = getLocalActivityManager().startActivity(id, intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
if (window != null) {
stack.push(id);
setContentView(window.getDecorView());
}
}
public void pop() {
if (stack.size() == 1) finish();
LocalActivityManager manager = getLocalActivityManager();
manager.destroyActivity(stack.pop(), true);
if (stack.size() > 0) {
Intent lastIntent = manager.getActivity(stack.peek()).getIntent();
Window newWindow = manager.startActivity(stack.peek(), lastIntent);
setContentView(newWindow.getDecorView());
}
}
}
从 Fragment2_Activity1 使用以下代码调用 Activity2:
Intent intent = new Intent();
intent.setClass(getParent(), RelatedItemListActivity .class);
CouponsActivityGroup activityStack = (CouponsActivityGroup) getParent();
activityStack.push("SecondStackActivity", intent);
我现在面临的问题是
我想为Activity2设置一个过渡动画
从 Activity2 按下时 - 需要保持 Activity1(Fragment2_Activity1) 中的最后一个 Fragment 状态。
如何做到这一点?