我正在我的应用程序中实现选项卡。为此,我创建了一个类来处理选项卡内的活动。我的问题是我一个接一个地开始了一些活动,比如A、B、C、D。现在我想从D回到活动A,而其他活动如B、C和D应该被销毁。请帮我实现这一点。这是我用来处理活动的代码......
public class TabGroupActivity extends ActivityGroup {
protected Context mCTX;
protected ArrayList<String> mIdList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(mIdList == null){
mIdList = new ArrayList<String>();
}
//set context
mCTX = this;
}
public void startChildActivity(String Id, Intent intent){
Id+= System.currentTimeMillis();
Window window = getLocalActivityManager().startActivity(Id,intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
if (window != null) {
mIdList.add(Id);
setContentView(window.getDecorView());
}
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
int length = mIdList.size();
if(length > 0){
Activity current = getLocalActivityManager().getActivity(mIdList.get(length-1));
current.finish();
}
}
@Override
public void finishFromChild(Activity child) {
LocalActivityManager manager = getLocalActivityManager();
int index = mIdList.size()-1;
if (index < 1) {
finish();
return;
}
manager.destroyActivity(mIdList.get(index), true);
mIdList.remove(index);
index--;
String lastId = mIdList.get(index);
Intent lastIntent = manager.getActivity(lastId).getIntent();
Window newWindow = manager.startActivity(lastId, lastIntent);
setContentView(newWindow.getDecorView());
}
}
当我开始活动时,我将使用以下代码。
Intent locIntent = new Intent(HomeActivity.this,SomeActivity.class);
TabGroupActivity parent = (TabGroupActivity) getParent();
parent.startChildActivity("some id", locIntent);
我还有一个疑问......如何将一个选项卡中的活动切换到另一个选项卡中的活动。提前致谢